On Dec 11, 2011, at 8:35 AM, Amir Sasson wrote:
> After setting expire_on_commit to False, I hit inconsistency after
> commits in DB relations.
> For example, I've two tables Host and HostPort, where Host have a
> relation to Ports:
>
> class HostPort(Base):
> __tablename__ = 'hostport'
> db_id = Column('id', Integer, primary_key=True) # the port's id
> db_host_id = Column('host_id', Integer, ForeignKey('host.id'))
> db_host = relation("HostDb")
>
> class Host(Base):
> __mapper_args__ = {'polymorphic_identity' : 'single'}
> __tablename__ = 'host'
> db_id = Column('id', Integer, primary_key=True) # the host's id
> db_name = Column('name', String(100))
> db_ports = relation("HostPortDb")
>
> After I create a new HostPort (with an existing host as the host_id)
> and queries the host for it ports I do not get the newly created port.
> This problem did not occur when expire_on_commit was set to True.
>
> As I understand the problem occures since the appropriate host
> instance is not expired after the commit.
>
> Is there any way overcome this issue, without expiring all the DB
> instances ?
The "dynamic" relationship will emit a SELECT each time, there's that which
might be simplest here, or manually expire the contents of Host.db_ports with
session.expire(host, ['db_ports']).
http://www.sqlalchemy.org/docs/orm/collections.html?highlight=dynamic%20relationship#dynamic-relationship-loaders
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.