On 2014-02-01 00:09, Michael Bayer wrote:
> 
> On Jan 31, 2014, at 5:24 PM, lars van gemerden <l...@rational-it.com
> <mailto:l...@rational-it.com>> wrote:
> 
>> Hi, all
>>
>> I am running into these 2 errors and have run out of ideas what to do
>> about it (also because i don't what they mean); They seem to happen in
>> exactly the same circumstances.
>>
>>     mapper, table, update)
>>   File "build\bdist.win32\egg\sqlalchemy\orm\persistence.py", line
>> 514, in _emit_update_statements
>>     (table.description, len(update), rows))
>> StaleDataError: UPDATE statement on table 'Company' expected to update
>> 1 row(s); 0 were matched.
> 
> this means an object was meant to be UPDATEed via the ORM, however the
> row which is the target of the UPDATE is missing.  Either the primary
> key of this row changed somehow, or the row was deleted, *or* the row is
> not visible to your transaction (this seems to be your case).

I am running into something very similar:

StaleDataError: UPDATE statement on table 'buildings' expected to update
1 row(s); 0 were matched.

However this case is very simple, just a single row in a table, and it
looks to get selected just before the update (in the same transaction).
Nothing is being deleted.

The update:

    UPDATE buildings SET glatitude=%s, glongitude=%s WHERE buildings.id = %s

The columns:

    id         = Column(BigInteger, autoincrement=True, primary_key=True)
    glatitude  = Column(Numeric(precision=11, scale=8))
    glongitude = Column(Numeric(precision=11, scale=8))

What's interesting is that the error occurs only if glatitude and
glongitude are being updated to the same values that are already in the
database (i.e.: no real update).
When the old values are NULL or otherwise different than the new values,
everything works fine!

Is this a bug?

This is SQLAlchemy 0.9.1:

  File "[...]/sqlalchemy/orm/session.py", line 765, in commit
    self.transaction.commit()
  File "[...]/sqlalchemy/orm/session.py", line 370, in commit
    self._prepare_impl()
  File "[...]/sqlalchemy/orm/session.py", line 350, in _prepare_impl
    self.session.flush()
  File "[...]/sqlalchemy/orm/session.py", line 1879, in flush
    self._flush(objects)
  File "[...]/sqlalchemy/orm/session.py", line 1997, in _flush
    transaction.rollback(_capture_exception=True)
  File "[...]/sqlalchemy/util/langhelpers.py", line 57, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "[...]/sqlalchemy/orm/session.py", line 1961, in _flush
    flush_context.execute()
  File "[...]/sqlalchemy/orm/unitofwork.py", line 370, in execute
    rec.execute(self)
  File "[...]/sqlalchemy/orm/unitofwork.py", line 523, in execute
    uow
  File "[...]/sqlalchemy/orm/persistence.py", line 59, in save_obj
    mapper, table, update)
  File "[...]/sqlalchemy/orm/persistence.py", line 528, in
_emit_update_statements
    (table.description, len(update), rows))
StaleDataError: UPDATE statement on table 'buildings' expected to update
1 row(s); 0 were matched.

-- 
http://people.eisenbits.com/~stf/
http://www.eisenbits.com/

OpenPGP: 80FC 1824 2EA4 9223 A986  DB4E 934E FEA0 F492 A63B

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to