-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closes #19002: Module type profiles #19014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3014603 to
67eed72
Compare
6c14a57 to
96462e9
Compare
|
Would it make sense to add the supported |
|
@alehaa I considered that as part of the planning for this FR, but wasn't happy with the idea of having to define the constraint for every module bay, and defining it on the template feels a bit hacky IMO. At any rate, I opted to punt on it for now as there's already a lot going on in this FR. You're certainly welcome to open a new FR for it if you'd like. I almost did but wasn't sure if we'd be able to get to it in time for v4.3. |
|
Resolved |
|
Resolved |
|
|
|
Resolved |
|
There's a weird oddity with the HTML form when switching from a float (decimal) to an integer. Assuming an initial attribute value of 1.5, the form field will render as below, with no Because there's no step attribute, a default step value of 1 is assumed. Unfortunately, this means the field only accept values ending in .5 (0.5, 1.5, 2.5, etc.), and the user is stuck: Integer values fail frontend validation and decimal values fail backend validation. I'm not sure how best to work around this. Attempting to re-cast the initial value could lead to data loss, so we probably want to avoid that. The cleanest approach would be to enforce validation against existing attributes whenever the schema is changed. Edit: I ended up just using Django's FloatField for both integers and decimals to work around this. The appropriate validation is still enforced on the backend. |
This is due to bug #19023 (for which a PR is currently open). Once the fix for that is available, I'll merge it here and confirm. |
jnovinger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted some bugs in regular PR comments. This review also has a couple of questions.
| field = f'{self.attributes_field_name}__{key.split(self.attribute_filter_prefix, 1)[1]}' | ||
| self.attr_filters[field] = value | ||
|
|
||
| super().__init__(data=data, queryset=queryset, request=request, prefix=prefix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AttributeFiltersMixin seems to have some interesting characteristics. For instance, the following query string works for finding CPUs module types with 12 or 120 or even 512 cores: ?attr_cores__icontains=12.
I suppose that not necessarily bad, just wondering if it's intended for a string-style lookup to work on an attribute specified as an integer. It does ignore things that don't make sense as lookups like (?attr__jason=jason when there's no jason attribute), which seems to be the correct behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, this got me to wondering if I could use __isnull on an attribute that is not required. When I tried ?attr_core__isnull=True I got a surprising result: ValueError: The QuerySet value for an isnull lookup must be True or False.
I think this probably points to the need to clamp down on what lookups are allowed for attributes. Otherwise, I think we'll playing whackamole as people try things we didn't think of.
Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into this a bit but I don't think there's much we can do here realistically. The filterset can't know ahead of time what type of queries to enforce, and module types assigned different profiles may have overlapping fields. For example, one profile might declare an integer named foo and another profile a string named foo. There's no way to reconcile these when filtering for ?foo=, other than perhaps making some assumptions based on the value passed.
The only way I can think of to lock this down reliably would be to exclude anything other than exact lookups on attributes, but that would remove a substantial amount of functionality from the feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an incredibly fair point.
Any thoughts on the __isnull lookup issue? I don't think it would be as big a deal if it just silently ignored it, but raising a ValueError and causing a 500 seem pretty not ideal.
|
{
"properties": {
"aliases": {
"type": "array"
},
"architecture": {
"type": "string"
},
"cores": {
"minimum": 1,
"multipleOf": 2,
"type": "number"
},
"speed": {
"maximum": 1,
"minimum": 0.5,
"multipleOf": 0.01,
"type": "number"
}
}
}Resolved |
| schema = forms.JSONField( | ||
| label=_('Schema'), | ||
| required=False | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that schema values of null and "" don't affect any change on the items selected. However, I noticed that {} does essentially clear the schemas of the selected items.
This might be the intended behavior, but was not super intuitive.
Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relatedly, true and false literals were accepted as valid input for this field, even though they don't necessarily make sense.
Perhaps values should be locked down to some representation of no schema (null or {} perhaps) and some schema that is at least of type object. Not sure, though, just thinking out loud.
Resolved
I went ahead and snagged the review for that one. It's been merged. |
jnovinger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💥
Closes: #19002
modules.pyprofileForeignKey andattribute_dataJSONField on ModuleType