I've got a relatively complicated structure and I've been trying to get a minimal working example that breaks but I haven't been able to.
Here is approximately what my table structure is like:
class Table1(_db.Entity):
name = Required(str)
table2s = Set('Table2')
class Table2(_db.Entity):
height = Required(Decimal)
length = Required(Decimal)
table1 = Optional('Table1')
composite_key(height, length, table1)
with db_session:
Table2(height=2, length=1)
try:
Table2.exists(height=2, length=1) # This will throw an error
except AssertionError:
Table2.exists(height=2, length=1) # This works
In Table2 when I have the equivalent of a composite_key(height, length)
the code works fine. However, when I have compmosite_key(height, length, table1)
then when doing the exists statement this returns an AssertionError
.
I went through some of the source code and have located some of the issues in the following lines:
I'm on version 0.7.6, installed with pip install pony
ln 1875: assert prev_vals != new_vals
in function db_update_composite_index
This starts because in line 4151:
obj = cache_index.get(pkval)
is pulled incorrectly(?).
obj._dbvals_
doesn't have the entry which is None.
Then in line 4591 if old_dbval = get_dbval(attr, NOT_LOADED)
old_dbval defaults to NOT_LOADED which leads to an attribute to not be deleted.
This leads to entering the if statement
loop in line 4616 if any(attr in avdict for attr in attrs)
and erroring out on the cache.db_update_composite_index(obj, attrs, prev_vals, new_vals)
because prev_vals == new_vals
This is more like issue reply, not question answer. It was bug in Pony. We've fixed it here Thanks for reporting.