Skip to content

Conversation

pombredanne
Copy link
Member

This PR addresses some issues when serializing a PackageURL object to native types with the to_dict() method: the qualifiers were returned always as a regular, non-ordered mapping instead of a string.

With this PR, the signature has been update to to_dict(encode=False) . If encode is True, the qualifiers will be returned as a string and not a mapping.

If encode is False the mapping returned qualifiers is always an OrderedDict and not a plain dict().

The django_contrib model mixin has been updated accordingly.

Calling PackageURL.to_dict(encode=True) will return a string instead of
a mapping. Otherwise we now always use and return OrderedDict for
qualifiers

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Before this, we were saving a dict() in the qualifiers field of
PackageURLMixin resulting in damaged data (Django being smart enough
would serialize the dict() to a string. That string would not be usable
to recreate a qualifiers mapping afterwards.


Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
@pombredanne pombredanne requested a review from tdruez December 21, 2018 13:45
Copy link
Collaborator

@tdruez tdruez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks!

@pombredanne
Copy link
Member Author

Thanks! merging

@pombredanne pombredanne merged commit 1294b27 into master Dec 21, 2018
@pombredanne pombredanne deleted the qualifiers-dict branch December 21, 2018 13:48
scovetta pushed a commit to scovetta/packageurl-python that referenced this pull request Sep 19, 2020
Signed-off-by: Michael Scovetta <michael.scovetta@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants