Hello, 

I have some SQLAlchemy-persisted instances of objects that have some 
relationships coming from a parallel execution with multiprocessing. When I 
reduce the results coming from the several processes, I need to merge some 
relationships (`satellite` and `ground_station` objects in the code below) 
since the associated object got another instance id during the 
multiprocessing execution and if I don't merge I get an error like this:

sqlalchemy.exc.InvalidRequestError: Can't attach instance <Satellite>; 
another instance with key <...> is already present in this session

Below the code responsible of this (where results is the reduced list 
coming from the multiprocessing execution)

for passage in results:
    # I need to merge since if coming from multiprocessing the instance
    # IDs change.
    passage.satellite = session.merge(passage.satellite)
    passage.ground_station = session.merge(passage.ground_station)
    session.add(passage)


This was working as expected when an attribute `satellite.tle` was 
persisted in the database. I was asked now to remove that persistence from 
the DB. So that attribute is present at runtime, but it's not in the 
columns of the DB. `session.merge` now returns an objects where that `tle` 
attribute is not present anymore. 

So in the call:
passage.satellite = session.merge(passage.satellite)

the `satellite` object within `session.merge` correctly has the `tle` object, 
while the returned object from `session.merge` does not. Is there a way to 
avoid that merge strips off the attributes that are not persisted in the 
database?

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to