Commits

Pierre Carbonnelle committed b367187

run garbage collector before accessing pyDatalog.metaMixin.__refs__[cls]

Comments (0)

Files changed (2)

pyDatalog/examples/test.py

     assert not (~Z.x(z))
     assert ~Z.x(w)
     assert ~ (Z.z[w]=='z')
-    assert(Z.pred(X)) == [(w,)]
+    assert(Z.pred(X)) == [(w,)] # not duplicated !
     assert(Z.pred(X) & ~ (Z.z[X]>='z')) == [(w,)]
     assert(Z.x(X) & ~(Z.pred(X))) == [(z,)]
 

pyDatalog/pyEngine.py

 * variable bindings in a closure.  See http://tiny.cc/7837cw, http://tiny.cc/rq47cw
 """
 import copy
+import gc
 from itertools import groupby
 import re
 import six
                 fact_candidate(subgoal, class0, result)
             return        
         try: # call class._pyD_query
-            for result in _class._pyD_query(literal.pred.name, terms):
+            resolver = _class._pyD_query
+            if not _class.has_SQLAlchemy : gc.collect() # to make sure pyDatalog.metaMixin.__refs__[cls] is correct
+            for result in resolver(literal.pred.name, terms):
                 fact_candidate(subgoal, class0, result)
             if Debug : print("pyDatalog has used _pyD_query resolvers for %s" % literal)
             return
             
     if class0: # a.p[X]==Y, a.p[X]<y, to access instance attributes
         try: 
-            iterator = class0.pyDatalog_search(literal)
+            resolver = class0.pyDatalog_search
+            if not class0.has_SQLAlchemy : gc.collect() # to make sure pyDatalog.metaMixin.__refs__[cls] is correct
             if Debug : print("pyDatalog uses pyDatalog_search for %s" % literal)
-            for result in iterator:
+            for result in resolver(literal):
                 fact_candidate(subgoal, class0, result)
             return
         except AttributeError: