Hello All,
Assume you have a CompositeProperty that depends on two properties,
'property_1' and 'property_2' and assume the constructor method for this
property class does something like this:
class ExampleCompositeProperty(object):
def __init__(self, property_1, property_2):
if property_1 is None:
raise ValueError
Now say that you have a instance that looks like this:
row.example_composite_property == ExampleCompositeProperty('old_val_1',
'old_val_2')
Then you do this:
row.example_composite_property = ExampleCompositeProperty('old_val_1',
'new_val_2')
Then the code in the function below
https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/orm/descriptor_props.py#L332
will produce the following outcome for the 'added' and 'deleted' arrays:
added = ['old_val_1', 'new_val_2']
deleted = [None, 'old_val_2']
Then when it tries to instantiate the composite class on this line:
https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/orm/descriptor_props.py#L359
It will cause the ValueError exception raised by the __init__ method above.
Is this a problem with my model or with SqlAlchemy's get_history
implementation?
For now, I'm working around this issue by overriding get_history() and
replacing this part:
if hist.deleted:
deleted.extend(hist.deleted)
else:
deleted.append(None)
With this:
if hist.deleted:
deleted.extend(hist.deleted)
elif hist.unchanged:
deleted.extend(hist.unchanged)
else:
deleted.append(None)
Which seems symmetrical to what happens with the 'added' array. However,
I'm not 100% sure that this is a general solution to this problem.
Samer
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.