I have a problem with updating custom types in SQLAlchemy, issue is
that when I modify object attributes they are not detected as
modified. E/g:
# python class to work with
class BDelta(object):
def __init__(self):
self.id = None
self.flags = None
self.deltas = []
def __repr__(self):
deltas = ", ".join(["%s" % delta for delta in self.deltas])
res = '(%s, %s, ARRAY[%s])::bdelta' % (self.id, self.flags,
deltas)
return res
# SQLAlchemy type representing BDelta
class PGBDelta(sqltypes.TypeEngine):
def copy_value(self, value):
if value is None:
return None
else:
return deepcopy(value)
def compare_values(self, x, y):
print "compare_values - %s %s" % (repr(x), repr(y))
return x == y
def bind_processor(self, dialect):
def process(value):
return value
return process
def result_processor(self, dialect):
def process(value):
return value
return process
def get_col_spec(self):
return 'bdelta'
Table definition:
tmptbl_table = sa.Table("tmptbl", meta.metadata,
sa.Column("id", sa.types.Integer,
primary_key = True),
sa.Column("test_ints", PGArray
(sa.types.Integer)),
sa.Column("bdarr", PGArray(PGBDelta))
)
class Tmptbl(object):
@staticmethod
def Get(tid):
return meta.Session.query(Tmptbl).get(tid)
orm.mapper(Tmptbl, tmptbl_table)
Test function:
def test_func():
x = Tmptbl.Get(108)
x.bdarr[0].id = randint(0, 100)
meta.Session.flush()
meta.Session.commit()
Problem is that nothing is flushed in that case, because
x._sa_instance_state.mutable_dict['bdarr'] and
x._sa_instance_state.dict['bdarr'] are the same list of BDelta objects
and when I change property of one of those objects, changes are made
to both dict and mutable_dict, so SQLAlchemy doesn't find any
difference when flushing.
Question is: is there any way to fix that, make full copy of values on
"get" or something.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---