CachingQuery fails merging objects without any obvious pattern

Issue #2057 resolved
Former user created an issue

Traceback (most recent call last): File "/home/errormator/errormator/errormator/security.py", line 22, in init self.application = Resource.by_resource_id(application_id) File "/home/errormator/errormator/errormator/models.py", line 609, in by_resource_id return q.first() File "/home/errormator/python/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 1677, in first ret = list(self0:1) File "/home/errormator/python/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 1574, in getitem return list(res) File "/home/errormator/errormator/errormator/lib/sqlalchemy_ext/init.py", line 83, in iter return self.get_value(createfunc=lambda: list(Query.iter(self))) File "/home/errormator/errormator/errormator/lib/sqlalchemy_ext/init.py", line 103, in get_value ret = self.merge_result(ret, load=False) File "/home/errormator/python/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 1914, in merge_result for instance in iterator] File "/home/errormator/python/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1249, in _merge "merge() with load=False option does not support " InvalidRequestError: merge() with load=False option does not support objects marked as 'dirty'. flush() all changes on mapped instances before merging with load=False.

Comments (3)

  1. Former user Account Deleted

    this error happens in other places too, i should note that i tried testing something in my app and:

    @classmethod
    def by_user_name(cls, user_name, cache=FromCache("default_term", "by_user_name"),
                    invalidate=False):
        q = DBSession.query(cls).filter(cls.user_name == user_name)
        print DBSession.dirty
        if cache:
            q = q.options(sa.orm.eagerload(User.groups))
            q = q.options(cache)
        if invalidate:
            q.invalidate()
        print DBSession.dirty
        return q.first()
    

    session shows that object is not marked as dirty

    IdentitySet([]) IdentitySet( IdentitySet([)) 2011-02-14 06:02:00,917 ERROR errormator.handlers.util5 Traceback (most recent call last): ...SNAP....

    "merge() with load=False option does not support "
    

    InvalidRequestError: merge() with load=False option does not support objects marked as 'dirty'. flush() all changes on mapped instances before merging with load=False.

  2. Mike Bayer repo owner

    The pattern is, objects in the cache can't have any pending changes on them when load=False. If you throw a pdb.set_trace() into your iter() method, take a look at session.is_modified(obj), attributes.get_history(obj, attrname), that will reveal what modifications have occurred on the objects.

    K guess we're talking on irc, there's likely no bug here

  3. Log in to comment