On Aug 11, 2013, at 3:06 PM, csdr...@gmail.com wrote: > I'm having problem with the following code which is designed to remove an > object identified as malformed prior to session.commit(): > > if tickers[x] not in existing_tickers and company_names[x] not in > existing_companies: > company = Company(tickers[x], company_names[x], creators[x], links[x]) > session.add(company) > new_companies.append(company) > > bad_ticks = [] > for company in new_companies: > if company.get_prices() == False: > bad_ticks.append(company) > for tick in bad_ticks: > session.expunge(tick) > session.commit() > > I receive the following error: > > /Library/Python/2.7/site-packages/sqlalchemy/orm/dependency.py:746: > SAWarning: Object of type <Company> not in session, add operation along > 'Creator.companies' won't proceed > uowcommit, "add")
this is not an error, it's a warning. It means you have a Company object inside of the "companies" collection of a Creator; the Creator object is being flushed. However, as the unit of work traverses the "companies" collection, it will skip this particular Company object since it is not part of this Session and continue with the rest of the collection. There's no error, it's just a warning that this might not be what you want. > > > My guess is that the Company is getting expunged from the session but the > corresponding Creator isn't, if you want Creator to be expunged when a collected Company is expunged, you'd need to add the "expunge" cascade to the Company.creator relationship: class Company(Base): # ... creator = relationship("Creator", cascade="save-update, merge, expunge", ...)
signature.asc
Description: Message signed with OpenPGP using GPGMail