copy_field only makes a shallow copy of tagged values dictionary

Bug #1822317 reported by Colin Watson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lazr.restful
New
Undecided
Unassigned

Bug Description

An idiom I use from time to time in Launchpad is something like this in an interface, with _api_get_path being a property in the corresponding model:

    git_path = TextLine(
        title=_("Git branch path"), required=False, readonly=False,
        description=_(
            "The path of the Git branch containing a snap/snapcraft.yaml, "
            "snapcraft.yaml, or .snapcraft.yaml recipe at the top level."))
    _api_git_path = exported(
        TextLine(
            title=_("Git branch path"), required=False, readonly=False,
            description=_(
                "The path of the Git branch containing a snap/snapcraft.yaml, "
                "snapcraft.yaml, or .snapcraft.yaml recipe at the top "
                "level.")),
        exported_as="git_path")

It would be nice to be able to write the second assignment as something like this instead:

    _api_git_path = exported(copy_field(git_path), exported_as="git_path")

Unfortunately this fails in confusing ways because copy_field only makes a shallow copy of the field's Element.__tagged_values dictionary, so exported() in fact sets tagged values on both the original and the copied field, which in turn causes some webservice operations to operate on the underlying attribute rather than the property accessor that I'd intended to wrap it in.

If possible, I think copy_attribute (and hence copy_field) should do a deep copy rather than a shallow copy, but it's possible that that might break other things. Failing that, it should at least arrange for there to be separate Element.__tagged_values dictionaries in the original and copied fields.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.