On 06/09/2010 12:44 AM, Az wrote:
> Traceback (most recent call last):
>   File "Main.py", line 39, in <module>
>     MCS.monteCarloBasic(trials)
>   File "/XXXX/MonteCarloSimulation.py", line 163, in monteCarloBasic
>     session.merge(temp_alloc)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/
> session.py", line 1158, in merge
>     self._autoflush()
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/
> session.py", line 897, in _autoflush
>     self.flush()
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/
> session.py", line 1354, in flush
>     self._flush(objects)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/
> session.py", line 1432, in _flush
>     flush_context.execute()
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/
> unitofwork.py", line 261, in execute
>     UOWExecutor().execute(self, tasks)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/
> unitofwork.py", line 753, in execute
>     self.execute_save_steps(trans, task)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/
> unitofwork.py", line 768, in execute_save_steps
>     self.save_objects(trans, task)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/
> unitofwork.py", line 759, in save_objects
>     task.mapper._save_obj(task.polymorphic_tosave_objects, trans)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/orm/
> mapper.py", line 1428, in _save_obj
>     c = connection.execute(statement.values(value_params), params)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/
> engine/base.py", line 824, in execute
>     return Connection.executors[c](self, object, multiparams, params)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/
> engine/base.py", line 874, in _execute_clauseelement
>     return self.__execute_context(context)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/
> engine/base.py", line 896, in __execute_context
>     self._cursor_execute(context.cursor, context.statement,
> context.parameters[0], context=context)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/
> engine/base.py", line 950, in _cursor_execute
>     self._handle_dbapi_exception(e, statement, parameters, cursor,
> context)
>   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/
> engine/base.py", line 931, in _handle_dbapi_exception
>     raise exc.DBAPIError.instance(statement, parameters, e,
> connection_invalidated=is_disconnect)
> sqlalchemy.exc.IntegrityError: (IntegrityError) columns uid,
> session_id, stud_id are not unique u'INSERT INTO sim_alloc (ident,
> uid, session_id, stud_id, alloc_proj, alloc_proj_rank) VALUES
> (?, ?, ?, ?, ?, ?)' [1, '1d295f48-7386-11df-8e87-00264a052efc', 1,
> 5796, 1100009, 1]
>
> ########
>
> Good news: Got the UUID working in a snap.
> Bad news: See error :(
>
>
> Note: This happened when I started using 'session.merge(temp_alloc)'
> instead of 'session.add'
>   

The most likely cause is if you call session.add(temp_alloc) after
calling session.merge(temp_alloc) for the same temp_alloc object. I
noticed your original monteCarloBasic had two calls to
session.add(temp_alloc); did both get changed to
session.merge(temp_alloc)? If that doesn't work, can you verify that
SQLAlchemy's primary key for SimAllocation matches the database's
primary key for sim_alloc? What column type are you using for uid? Which
call to session.merge is failing (line 163 according to your traceback),
the one inside your "for rank in ranks" loop or the one outside?

Also, since you know you are creating new sim_alloc rows in the database
(instead of overwriting existing ones), you can use session.add instead
of session.merge. This will prevent unnecessary SELECTs to your database.

-Conor

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to