Skip to content

Commit c486db4

Browse files
committed
Set qualifiers as a string when setting fields
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>
1 parent 0f5e632 commit c486db4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/packageurl/contrib/django_models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ def package_url(self):
112112

113113
def set_package_url(self, package_url):
114114
"""
115-
Set values for each related field of the provided `package_url` string.
116-
Empty/Null values are normalized to `None` and are set as well
117-
to replace any existing values.
118-
This prevent mixing newly provided values with old ones.
115+
Set each field values to the values of the provided `package_url` string
116+
or PackageURL object. Existing values are overwritten including setting
117+
values to None for provided empty values.
119118
"""
120-
purl = PackageURL.from_string(package_url)
119+
if not isinstance(package_url, PackageURL):
120+
package_url = PackageURL.from_string(package_url)
121121

122-
for field_name, value in purl.to_dict().items():
122+
for field_name, value in package_url.to_dict(encode=True).items():
123123
setattr(self, field_name, value or None)

0 commit comments

Comments
 (0)