it seems like you might be modifying primary key values of entities.   
the ConcurrencyError youre getting is strictly because SA is trying  
to say:

        UPDATE table SET <entity values>  WHERE primarykeycol = pk [AND  
pkcol2=pk2 [AND pkcol3=pk3 ...] ]

and the number of affected rows, which should be one, is coming out  
as zero.   You either have some plain SQL changing  primary key  
column values in the table, some other process is deleting the  
entities concurrently, or you are screwing around with the primary  
key attributes of your entities before saving them.  SA's orm, like  
most (if not all) ORMs, assumes the primary key values of an entity  
are immutable (not that you cant change them outside of the ORM, but  
just dont expect the ORM to figure out what you did unless you  
refresh the session with new data).


On Aug 14, 2006, at 10:25 AM, Brian Jarrett wrote:

> More on this:
> I've loaded 0.2.7 and I'm still getting this error, but it happens
> only when I add more fields to be updated.  I have a script that looks
> for a record, if it's not found, it adds it, if it IS found, it
> updates just certain fields.  I went back into my script, after having
> done a run that added many records, and added a few more fields that I
> wanted to update, then I started getting this error, and only on a few
> records out of the whole import.  If I remove the fields I added to be
> updated, then it works fine, updating the information I had already
> specified.
>
> Any clues?  I really need this to work correctly.
>
> Brian
>
>
> On 8/10/06, Brian Jarrett <[EMAIL PROTECTED]> wrote:
>> Hello list,
>>
>> Using SA 0.2.4, I'm getting a ConcurrencyError and I don't know  
>> how to
>> resolve it.  I'm getting data from a CSV file one line at a time and
>> updating objects mapped to a postgres table.  Most of the data  
>> updates
>> fine, just certain lines seem to be causing issues.  The __dict__ of
>> the object I'm trying to update (after updating with new data) is:
>>
>> {'_AttributeManager__sa_attr_state': {'modified': True,
>>                                       'original': CommittedState:
>> {'modified_date': None, 'modified_by': None, 'syear': Decimal 
>> ("2005"),
>> 'end_date': datetime.date(2005, 8, 22), 'student_id':
>> Decimal("120270089"), 'start_date': datetime.date(2004, 8, 20),
>> 'school_id': Decimal("1"), 'scheduler_lock': None, 'mp': None,
>> 'course_period_id': Decimal("3115"), 'course_id': Decimal("678"),
>> 'marking_period_id': None, 'id': Decimal("133"), 'course_weight':
>> 'Zero'}},
>>  '_Schedule__sa_attr_state': {},
>>  '_entity_name': None,
>>  '_instance_key': (<class 'database.Schedule'>,
>>                    (Decimal("2005"),
>>                     Decimal("120270089"),
>>                     Decimal("678"),
>>                     'Zero',
>>                     Decimal("3115"),
>>                     datetime.date(2004, 8, 20)),
>>                    None),
>>  '_sa_session_id': 14308368,
>>  'course_id': Decimal("678"),
>>  'course_period_id': Decimal("3115"),
>>  'course_weight': 'Zero',
>>  'end_date': '08/22/2005',
>>  'id': Decimal("133"),
>>  'marking_period_id': None,
>>  'modified_by': None,
>>  'modified_date': None,
>>  'mp': None,
>>  'scheduler_lock': None,
>>  'school_id': Decimal("1"),
>>  'start_date': '08/22/2005',
>>  'student_id': Decimal("120270089"),
>>  'syear': Decimal("2005")}
>>
>>
>> This is what I get with echo_uow=True (nothing to see here, really.):
>>
>> Task dump:
>>
>>  UOWTask(15073328, Schedule/schedule/None)
>>   |- Save Schedule(15073584)
>>   |----
>>
>>
>> And finally, the exception raised:
>>
>> FlushError: ConcurrencyError - updated rowcount 0 does not match
>> number of objects updated 1
>> Traceback:
>>   File "<string>", line 1, in ?
>>   File "c:\Python24\projects\basejumper\APSCNparser.py", line 636,  
>> in ?
>>     session.flush()
>>   File "C:\Python24\lib\site-packages\sqlalchemy\orm\session.py",  
>> line
>> 233, in flush
>>     self.uow.flush(self, objects, echo=self.echo_uow)
>>   File "C:\Python24\lib\site-packages\sqlalchemy\orm\unitofwork.py",
>> line 228, in flush
>>     flush_context.execute(echo=echo)
>>   File "C:\Python24\lib\site-packages\sqlalchemy\orm\unitofwork.py",
>> line 399, in execute
>>     head.execute(self)
>>   File "C:\Python24\lib\site-packages\sqlalchemy\orm\unitofwork.py",
>> line 667, in execute
>>     self._save_objects(trans)
>>   File "C:\Python24\lib\site-packages\sqlalchemy\orm\unitofwork.py",
>> line 621, in _save_objects
>>     task.mapper.save_obj(task.tosave_objects, trans)
>>   File "C:\Python24\lib\site-packages\sqlalchemy\orm\mapper.py", line
>> 808, in save_obj
>>     raise exceptions.FlushError("ConcurrencyError - updated rowcount
>> %d does not match number of objects updated %d" % (rows, len 
>> (update)))
>>
>>
>> it seems like every one of the ones having errors shows in the
>> _instance_key attribute a date of 2004-8-20, that doesn't match
>> anything I'm giving to the object.  How do I go about finding the
>> problem?
>>
>> Brian
>>
>
> ---------------------------------------------------------------------- 
> ---
> Using Tomcat but need to do more? Need to support web services,  
> security?
> Get stuff done quickly with pre-integrated technology to make your  
> job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache  
> Geronimo
> http://sel.as-us.falkag.net/sel? 
> cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to