Issue #8954
closedUsing form data doesn't set labels
Description
When setting pulp_labels using a request that sends form data, pulp_labels aren't getting set:
$ http --form -p b POST :/pulp/api/v3/remotes/file/file/ name=$RANDOM pulp_labels={"environment":"dev"} url='http://test'
{
"ca_cert": null,
"client_cert": null,
"connect_timeout": null,
"download_concurrency": null,
"headers": null,
"max_retries": null,
"name": "11512",
"policy": "immediate",
"proxy_url": null,
"pulp_created": "2021-06-23T13:08:15.205770Z",
"pulp_href": "/pulp/api/v3/remotes/file/file/9882755c-adf5-472f-ad13-b0c9728d1eb2/",
"pulp_labels": {},
"pulp_last_updated": "2021-06-23T13:08:15.205796Z",
"rate_limit": null,
"sock_connect_timeout": null,
"sock_read_timeout": null,
"tls_validation": false,
"total_timeout": null,
"url": "http://test"
}
This works though:
http -p b POST :/pulp/api/v3/remotes/file/file/ name=$RANDOM pulp_labels:="{\"environment\":\"dev\"}" url='http://test'
Not sure what the difference is. At the very least, we should probably be raising an error if the format is incorrect.
Related issues
Updated by dkliban@redhat.com over 3 years ago
- Triaged changed from No to Yes
- Sprint set to Sprint 99
Updated by lmjachky over 3 years ago
- Status changed from NEW to ASSIGNED
- Assignee set to lmjachky
Updated by lmjachky over 3 years ago
It looks like rest_framework
does not support dictionary form input (https://github.com/encode/django-rest-framework/blob/71e6c30034a1dd35a39ca74f86c371713e762c79/rest_framework/templates/rest_framework/inline/dict_field.html#L8) in the web UI. Furthermore, once the framework determines that a user passed data via an HTML form, it still tries to parse the data by searching for a regex match (https://github.com/encode/django-rest-framework/blob/71e6c30034a1dd35a39ca74f86c371713e762c79/rest_framework/utils/html.py#L69-L95). But, this approach will never find a match for pulp_labels
because the method searches for keys like pulp_labels.xyz
, in our case pulp_labels.environment
. Such a key is considered always invalid:
{
"pulp_labels.environment": [
"Unexpected field"
]
}
The solution is to replace DictField
(https://github.com/pulp/pulpcore/blob/3ca47373e4a33965da362e76bc269640f8dc6925/pulpcore/app/serializers/fields.py#L380) with JSONField
.
Updated by pulpbot over 3 years ago
- Status changed from ASSIGNED to POST
Updated by dalley over 3 years ago
- Related to Backport #9058: Backport 8954 "using form data doesn't set labels" to 3.14.z added
Added by Lubos Mjachky over 3 years ago
Updated by Anonymous over 3 years ago
- Status changed from POST to MODIFIED
Applied in changeset pulpcore|3bc707ad6aab45d76f06abab7ed0870049cc28f8.
Updated by ipanova@redhat.com over 3 years ago
- Sprint/Milestone changed from 3.14.2 to 3.15.0
Updated by pulpbot over 3 years ago
- Status changed from MODIFIED to CLOSED - CURRENTRELEASE
Replace DictField with JSONField
closes #8954