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")

Class Company() has a relationship with Class Creator() (referenced in 
error message). The relationship between Company and Creator is summarized 
briefly as follows:

class Company(Base):
    __tablename__ = "companies"
    creator = relationship("Creator", backref="companies")
    def __init__(self, ticker, company, creator, link):
        self.creator.append(Creator(creator))

class Creator(Base):
    __tablename__ = "creators"
    company_id = Column(Integer, ForeignKey('companies.id'))
    creator = Column(String(100), nullable=False)

A Creator can have a relationship with multiple Companies but any one 
Company can have a relationship with only one Creator.

My guess is that the Company is getting expunged from the session but the 
corresponding Creator isn't, and that's confusing MySql and/or sqlalchemy. 
However, I don't know how to try to expunge the Creator object since it's 
only ever called within the Company class. Anyone know the proper way to 
fix this?

Thanks,

Chris

-- 
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