validates decorator gets called twice while using merge
Issue #2533
resolved
The @validates decorator function gets called twice while using merge to add a new object to the database. I have tested this with 0.7.8 and I couldnt find any other related bugs.
Calling the following method with input "bar" results into "barbarbar"
@validates('data')
def _set_data(self, key, value):
print "Validating: %s\nType is: %s" % (value, type(value))
data = value + value
return data
Check the test script I have attached.
Comments (5)
-
repo owner -
repo owner - changed milestone to 0.7.9
-
Account Deleted Ok that makes sense.
As the value I want to store is modified in the first object and the second object cant get it back out in the original format.
Sorry for the unnecessary bug report.
-
repo owner - changed status to wontfix
-
repo owner - removed milestone
Removing milestone: 0.7.9 (automated comment)
- Log in to comment
Without even trying this, i'd guess that you're seeing the validator called twice because there are two different
Test
objects at play here - theTest
object you create via constructor, and theTest
object generated withinmerge()
. Note thatmerge()
leaves the object you pass in unchanged - it is essentially meant to copy state from an outside object to an instance that's inside the session.you can see/confirm this effect if you also print
self
in your_set_data()
routine.I'll give it a try later to confirm, but if so this would be a "worksforme". If you truly want there to be only one
Test
object at play you'd need to stick withadd()
, as well asget()
if you want to check for an existing identity.