appending tags to bug.tags is not supported properly on lp_save()
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
| launchpadlib |
Low
|
Unassigned |
Bug Description
Other then documented in the reference (http://
In [38]: b = launchpad.
In [39]: b.tags
Out[39]: [u'bar', u'foo']
In [40]: b.tags.
n [41]: b._dirty_attributes
Out[41]: {}
This only works for changing the complete object:
In [42]: b.tags = ["bood"]
In [43]: b._dirty_attributes
Out[43]: {'tags': ['bood']}
Markus
---
Workaround: rather than appending to the list, set the attribute to a new list that has the value you want:
Not: b.tags.
but rather: b.tags = b.tags + ['foo']
Markus Korn (thekorn) wrote : | #2 |
Hi Leonard,
thanks for your reply. I don not really care about monitoring changes to an object, I just choose this example to show why the following workflow is not working:
In [38]: b = launchpad.
In [39]: b.tags
Out[39]: [u'bar', u'foo']
In [40]: b.tags.
n [41]: b.lp_save()
This fails silently, because launchpadlib does not know about changes of mutable attributes of an object.
IMHO, changing the type of the tags attribute to a tuple or a string is not a good solution, the workflow described above is the most natural one.
Without knowing all the internals of launchpadlib I agree that wrapping it in a proxy object is not a good solution here. But what about storing mutable objects in a cache right after fetching the data, and when calling lp_save() compare the current value with the value in the cache. This way you know if a mutable object changed. - just my suggestion.
Markus
Barry Warsaw (barry) wrote : | #3 |
You could potentially inherit bug.tags from built-in list and do the overriding (i.e. proxying), but it's kind of a tricky situation. It reminds me of the workarounds that something like ZODB has to do.
The easiest thing to do would be to expose a method that allowed you to mark an attribute as dirty so that you could explicitly say, e.g. to save tags when you call lp_save().
I'm not sure the idea of caching the mutable objects is workable. They could be very large, and you'd have to keep a unique copy to do the comparison. You could just always save any mutable attributes, but I'm not sure that the wadl gives you that information.
So I think the simplest solution is also the most explicit:
>>> b.tags.
>>> b.lp_mark('tags')
>>> b.lp_save() # patches tags
Markus Korn (thekorn) wrote : | #4 |
I attached two branches to implement this workflow:
>>> b.tags.
>>> b.lp_save()
This is done in wadllib by implementing a subclass of list with an additional property 'changed' called ChangedList.
This class is used for the 'tags' attribute of the '#bug' namespace
Markus
Changed in launchpadlib: | |
importance: | Undecided → Low |
status: | Confirmed → Triaged |
Rick Spencer (rick-rickspencer3) wrote : | #5 |
I was pointed to a workaround:
#first create a fresh bug
bug = self.launchpad.
#then reassign the tags list
bug.tags = bug.tags + ['needs-bug-squad']
#then you can save it
bug.lp_save()
HTH until it is fixed
tags: | added: oem-services |
Facundo Batista (facundo) wrote : | #6 |
Maybe the easiest way to handle this, is not to make the tags attribute a list, but a tuple!
Nobody will try to modify the tuple, :)
Also, the docs should be fixed (https:/
Thanks!
Matt Zimmerman (mdz) wrote : | #7 |
Is there something wrong with the branches attached to this bug, which seem to fix the problem?
description: | updated |
Robert Collins (lifeless) wrote : | #8 |
Neither of the branches have been proposed for merging, and Markus hasn't (AFAICT) signed the canonical contributors agreement.
Markus, we'd love to incorporate these fixes - what you need to do is sign the canonical contributor agreement - http://
With both of those things done our code reviewers will be able to look at your branch and assess whether the fix is appropriate and ready to merge, or whether it needs further work done (which they may do, or may ask you to do).
Cheers,
Rob
Markus Korn (thekorn) wrote : | #9 |
I think I signed the agreement sometime back in 2009, I will check tomorrow, and see if these two branches are still mergeable. Since I haven't look at them for a long time.
Bryce Harrington (bryce) wrote : | #10 |
Hi Markus, can you confirm about the agreement?
Colin Watson (cjwatson) wrote : | #11 |
Markus, you don't seem to be a member of ~contributor-
It's not really practical to monitor a list for changes; we'd have to wrap it in a proxy object that knew about the entire Python list interface. We could prevent the problem by deserializing tags into a tuple rather than a list. Then you'd know you had to replace the tuple with another one.