Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1978 (closed defect: fixed)

Opened 11 years ago

Last modified 11 years ago

Tests fail on 1.9.7a4 quickstart app with identity

Reported by: dlatornell Owned by: Gustavo
Priority: normal Milestone:
Component: Tests Version: trunk
Severity: normal Keywords: quickstart
Cc:

Description

nosetests fails on a 1.9.7a4 quickstart app with identity at source:projects/tg.devtools/trunk/devtools/templates/turbogears/+package+/tests/__init__.py_tmpl#L33 See traceback below.

Removing lines 31-33 from tests/__init__.py allows the tests to pass.

Traceback:

(tg2a4)alec:HelloWorldId$ nosetests                  
E
======================================================================
ERROR: Failure: IntegrityError ((IntegrityError) column user_name is not unique u'INSERT INTO tg_user (user_name, email_address, display_name, password
, created) VALUES (?, ?, ?, ?, ?)' ['manager', 'manager@somedomain.com', 'Example manager', 'managepass', '2008-09-02 12:36:22.622806'])
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/doug/tg2a4/lib/python2.5/site-packages/nose-0.10.3-py2.5.egg/nose/loader.py", line 364, in loadTestsFromName
    addr.filename, addr.module)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/nose-0.10.3-py2.5.egg/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/nose-0.10.3-py2.5.egg/nose/importer.py", line 84, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/doug/tg2a4/HelloWorldId/helloworldid/tests/__init__.py", line 33, in <module>
    cmd.run([test_file])
  File "/home/doug/tg2a4/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/appinstall.py", line 68, in run
    return super(AbstractInstallCommand, self).run(new_args)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/command.py", line 213, in run
    result = self.command()
  File "/home/doug/tg2a4/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/appinstall.py", line 456, in command
    self, config_file, section, self.sysconfig_install_vars(installer))
  File "/home/doug/tg2a4/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/appinstall.py", line 600, in setup_config
    mod.setup_config(command, filename, section, vars)
  File "/home/doug/tg2a4/HelloWorldId/helloworldid/websetup.py", line 43, in setup_config
    model.DBSession.flush()
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/scoping.py", line 106, in do
    return getattr(self.registry(), name)(*args, **kwargs)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/session.py", line 1409, in flush
    flush_context.execute()
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 265, in execute
    UOWExecutor().execute(self, tasks)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 753, in execute
    self.execute_save_steps(trans, task)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 768, in execute_save_steps
    self.save_objects(trans, task)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/unitofwork.py", line 759, in save_objects
    task.mapper._save_obj(task.polymorphic_tosave_objects, trans)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/orm/mapper.py", line 1199, in _save_obj
    c = connection.execute(statement.values(value_params), params)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/engine/base.py", line 848, in execute
    return Connection.executors[c](self, object, multiparams, params)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/engine/base.py", line 899, in execute_clauseelement
    return self._execute_compiled(elem.compile(dialect=self.dialect, column_keys=keys, inline=len(params) > 1), distilled_params=params)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/engine/base.py", line 911, in _execute_compiled
    self.__execute_raw(context)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/engine/base.py", line 920, in __execute_raw
    self._cursor_execute(context.cursor, context.statement, context.parameters[0], context=context)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/engine/base.py", line 964, in _cursor_execute
    self._handle_dbapi_exception(e, statement, parameters, cursor)
  File "/home/doug/tg2a4/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/sqlalchemy/engine/base.py", line 946, in _handle_dbapi_exception
    raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect)
IntegrityError: (IntegrityError) column user_name is not unique u'INSERT INTO tg_user (user_name, email_address, display_name, password, created) VALUE
S (?, ?, ?, ?, ?)' ['manager', 'manager@somedomain.com', 'Example manager', 'managepass', '2008-09-02 12:36:22.622806']

----------------------------------------------------------------------
Ran 1 test in 0.195s

FAILED (errors=1)

Attachments

websetup.py_tmpl-patch-1978 Download (678 bytes) - added by dlatornell 11 years ago.
Patch to remove transaction code from websetup.py_tmpl

Change History

Changed 11 years ago by dlatornell

Patch to remove transaction code from websetup.py_tmpl

comment:1 follow-up: ↓ 3 Changed 11 years ago by dlatornell

Attached patch fixes this by deleting explicit transaction.commit() because 1.9.7a4 does automatic transactions. Also deletes model.DBSession.flush() statements because they trigger commits too (I think???).

comment:2 Changed 11 years ago by Gustavo

  • Status changed from new to assigned
  • Owner changed from anonymous to Gustavo

That code should not be removed because then websetup would have no effect.

What happens is that you're running the tests using the devdata.db, instead of the in memory database. So if you run websetup again, you'd be trying to re-add the same row - hence the integrity error. If you removed the devdata.db file before running the tests, you'll see it works.

So, thank you very much for bringing this up. By default it should be using the in memory database. I'm going to fix it.

comment:3 in reply to: ↑ 1 Changed 11 years ago by Gustavo

Replying to dlatornell:

Attached patch fixes this by deleting explicit transaction.commit() because 1.9.7a4 does automatic transactions.

BTW, that's only when you're running the web interface (in your controllers, you wouldn't need to commit explicitly).

comment:4 Changed 11 years ago by Gustavo

  • Status changed from assigned to closed
  • Resolution set to fixed

This is fixed in [5358]. To correct this bug in your app, you should add the following to your test.ini file below [app:main]:

sqlalchemy.url = sqlite:///:memory:

comment:5 Changed 11 years ago by anonymous

  • Milestone 1.9.7b1 deleted

Milestone 1.9.7b1 deleted

Note: See TracTickets for help on using tickets.