Project

Profile

Help

Issue #8954

closed

Using form data doesn't set labels

Added by daviddavis almost 3 years ago. Updated over 2 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Platform Release:
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Sprint 100
Quarter:

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

Related to Pulp - Backport #9058: Backport 8954 "using form data doesn't set labels" to 3.14.zCLOSED - CURRENTRELEASEdaviddavis

Actions
Actions #1

Updated by daviddavis almost 3 years ago

  • Description updated (diff)
Actions #2

Updated by dkliban@redhat.com almost 3 years ago

  • Triaged changed from No to Yes
  • Sprint set to Sprint 99
Actions #3

Updated by rchan almost 3 years ago

  • Sprint changed from Sprint 99 to Sprint 100
Actions #4

Updated by lmjachky almost 3 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to lmjachky
Actions #5

Updated by lmjachky almost 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.

Actions #6

Updated by pulpbot almost 3 years ago

  • Status changed from ASSIGNED to POST
Actions #7

Updated by dalley almost 3 years ago

  • Related to Backport #9058: Backport 8954 "using form data doesn't set labels" to 3.14.z added
Actions #8

Updated by dalley almost 3 years ago

  • Sprint/Milestone set to 3.14.2

Added by Lubos Mjachky almost 3 years ago

Revision 3bc707ad | View on GitHub

Replace DictField with JSONField

closes #8954

Actions #9

Updated by Anonymous almost 3 years ago

  • Status changed from POST to MODIFIED
Actions #10

Updated by ipanova@redhat.com almost 3 years ago

  • Sprint/Milestone changed from 3.14.2 to 3.15.0
Actions #11

Updated by pulpbot over 2 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF