Thanks Michael!

On Sunday, August 11, 2013 4:33:20 PM UTC-4, Michael Bayer wrote:
>
>
> On Aug 11, 2013, at 3:06 PM, csd...@gmail.com <javascript:> 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", ...)
>
>
>
>
>

-- 
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/groups/opt_out.


Reply via email to