issue #2896 is resolved for 0.8.5 and 0.9.0.

On Dec 20, 2013, at 10:03 AM, Michael Bayer <[email protected]> wrote:

> there’s a SQLAlchemy issue here, marked as ticket 
> http://www.sqlalchemy.org/trac/ticket/2896, however resolving this issue 
> still won’t fix your issue.  You’re emitting an INSERT on a table where the 
> primary key needs to refer to a column elsewhere.  that is:
> 
> task = Table('y', metadata,
>     Column('set_id', Integer, primary_key=True)
>     )
> dataset = Table("x", metadata,
>     Column("set_id", Integer,  primary_key=True)
> )
> dataset.append_constraint(ForeignKeyConstraint([dataset.c.set_id], 
> [task.c.set_id]))
> 
> 
> to insert a dataset row, the dataset must refer to a task row.   SQLite 
> doesn’t enforce foreign key constraints by default so that the INSERT will 
> proceed but the row will be relationally inconsistent.
> 
> also, if you aren’t planning on using Oracle as a backend, I’d remove the 
> Sequence directive from your program for now.   until #2896 is fixed it will 
> get in the way of allowing this issue to be clear.
> 
> 
> 
> 
> On Dec 20, 2013, at 5:50 AM, Massi <[email protected]> wrote:
> 
>> Hi, I'm experiencing a similar problem in my program (Sqlalchemy  0.8.4). In 
>> my case no blob column is involved, the problem seems to be related to 
>> presence of a foreign key in the target table. Here is the traceback of the 
>> error:
>> 
>>   File "C:\Python27\lib\site-packages\sqlalchemy\orm\session.py", line 721, 
>> in commit
>>     self.transaction.commit()
>>   File "C:\Python27\lib\site-packages\sqlalchemy\orm\session.py", line 354, 
>> in commit
>>     self._prepare_impl()
>>   File "C:\Python27\lib\site-packages\sqlalchemy\orm\session.py", line 334, 
>> in _prepare_impl
>>     self.session.flush()
>>   File "C:\Python27\lib\site-packages\sqlalchemy\orm\session.py", line 1818, 
>> in flush
>>     self._flush(objects)
>>   File "C:\Python27\lib\site-packages\sqlalchemy\orm\session.py", line 1936, 
>> in _flush
>>     transaction.rollback(_capture_exception=True)
>>   File "C:\Python27\lib\site-packages\sqlalchemy\util\langhelpers.py", line 
>> 58, in __exit__
>>     compat.reraise(exc_type, exc_value, exc_tb)
>>   File "C:\Python27\lib\site-packages\sqlalchemy\orm\session.py", line 1900, 
>> in _flush
>>     flush_context.execute()
>>   File "C:\Python27\lib\site-packages\sqlalchemy\orm\unitofwork.py", line 
>> 372, in execute
>>     rec.execute(self)
>>   File "C:\Python27\lib\site-packages\sqlalchemy\orm\unitofwork.py", line 
>> 525, in execute
>>     uow
>>   File "C:\Python27\lib\site-packages\sqlalchemy\orm\persistence.py", line 
>> 64, in save_obj
>>     table, insert)
>>   File "C:\Python27\lib\site-packages\sqlalchemy\orm\persistence.py", line 
>> 569, in _emit_insert_statements
>>     execute(statement, params)
>>   File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 662, 
>> in execute
>>     params)
>>   File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 761, 
>> in _execute_clauseelement
>>     compiled_sql, distilled_params
>>   File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 828, 
>> in _execute_context
>>     None, None)
>>   File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 1024, 
>> in _handle_dbapi_exception
>>     exc_info
>>   File "C:\Python27\lib\site-packages\sqlalchemy\util\compat.py", line 196, 
>> in raise_from_cause
>>     reraise(type(exception), exception, tb=exc_tb)
>>   File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 824, 
>> in _execute_context
>>     context = constructor(dialect, self, conn, *args)
>>   File "C:\Python27\lib\site-packages\sqlalchemy\engine\default.py", line 
>> 446, in _init_compiled
>>     self.__process_defaults()
>>   File "C:\Python27\lib\site-packages\sqlalchemy\engine\default.py", line 
>> 821, in __process_defaults
>>     val = self.get_insert_default(c)
>>   File "C:\Python27\lib\site-packages\sqlalchemy\engine\default.py", line 
>> 777, in get_insert_default
>>     return self._exec_default(column.default, column.type)
>>   File "C:\Python27\lib\site-packages\sqlalchemy\engine\default.py", line 
>> 761, in _exec_default
>>     return self.fire_sequence(default, type_)
>> StatementError: 'SQLiteExecutionContext' object has no attribute 
>> 'fire_sequence' (original cause: AttributeError: 'SQLiteExecutionContext' 
>> object has no attribute 'fire_sequence') u'INSERT INTO dataset (set_id, 
>> user_id, label, set_table, nam_table, val_table, datasource, info) VALUES 
>> (?, ?, ?, ?, ?, ?, ?, ?)' [{'info': None, 'user_id': 1, 'val_table': 
>> u'val_table', 'label': u'tab1', 'nam_tab': u'nam_table', 'set_table': 
>> u'tab1', 'datasource': None}]
>> 
>> The construct which causes the error is this:
>> dataset.append_constraint(sa.ForeignKeyConstraint([dataset.c.set_id], 
>> [task.c.set_id]))
>> 
>> If I remove this line of code everything goes well (but of course I cannot 
>> set up the relationship between the dataset table and the task table).
>> Any help is really appreciated.
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/sqlalchemy.
>> For more options, visit https://groups.google.com/groups/opt_out.
> 

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to