Remove the null=True on CharField fields of the PackageURLMixin #36 - #40
Conversation
Add a `empty=None` param on the `PackageURL.to_dict` method to allow custom value like empty string '' in place of None Signed-off-by: Thomas Druez <tdruez@nexb.com>
| raise ValidationError(message) | ||
|
|
||
| setattr(self, field_name, value or None) | ||
| setattr(self, field_name, value) |
There was a problem hiding this comment.
Have you considered setattr(self, field_name, value or '')?
There was a problem hiding this comment.
Yes I did. It was my initial approach, but the empty value is now controlled in the above to_dict which makes it unneeded in the setattr.
| data['qualifiers'] = normalize_qualifiers(self.qualifiers, | ||
| encode=encode) | ||
|
|
||
| if empty is not None: |
There was a problem hiding this comment.
Could you rephrase your question?
There was a problem hiding this comment.
Sorry for the poor wording ... I mean why would you only translate the empty values to empty if empty is not None?
Why not doing it all the time and therefore removing the test if empty is not None:?
| encode=encode) | ||
|
|
||
| if empty is not None: | ||
| data = OrderedDict((k, v or empty) for k, v in data.items()) |
There was a problem hiding this comment.
Since data is already an OrderedDict... you may want to modify it in place but this is minor:
for k, v in data.items():
data[k] = v or empty
Signed-off-by: Thomas Druez <tdruez@nexb.com>
|
@pombredanne This makes total sense and is definitely needed. It will prevent aboutcode-org/vulnerablecode#206 (comment) from happening. Thanks @tdruez |
|
@sbs2001 Thanks for your input 👍 |
Signed-off-by: Thomas Druez <tdruez@nexb.com>
…#36 Signed-off-by: Thomas Druez <tdruez@nexb.com>
From https://docs.djangoproject.com/en/3.0/ref/models/fields/#null
This is an issue when adding database constraints based on those fields as '' and null values do not behave the same.
Add a
empty=Noneparam on thePackageURL.to_dictmethod to allow custom value like empty string '' in place of NoneSigned-off-by: Thomas Druez tdruez@nexb.com