Open
Conversation
The pulp_labels_validator crashed with "expected string or bytes-like object" when a label value was null because re.search() doesn't accept None. Skip the regex check for None values since they are already accepted by the set_label endpoint and HStoreField. closes pulp#6593 Assisted-by: Claude (Cursor) Made-with: Cursor
2d8491e to
4a5c471
Compare
mdellweg
reviewed
Mar 5, 2026
| ], | ||
| ) | ||
| def test_pulp_labels_validator_valid(labels): | ||
| """Valid label values including None should pass validation.""" |
Member
There was a problem hiding this comment.
This comment is out of place. You could use pytest.param with id to add the intention to individual parameterizations.
pulpcore/app/serializers/fields.py
Outdated
| if not re.match(r"^[\w ]+$", k): | ||
| raise serializers.ValidationError(_("Key '{}' contains non-alphanumerics.").format(k)) | ||
| if re.search(r"[,()]", v): | ||
| if not re.match(r"^[\w .\-]+$", k): |
Member
There was a problem hiding this comment.
Not sure it's worth having a compiled version of this. But since you already needed to consolidate this RegEx in more than one place, shouldn't we have a single definition for it?
The three places validating label keys (pulp_labels_validator, SetLabelSerializer/UnsetLabelSerializer, and LabelFilter) each allowed different characters, making it possible to create labels that couldn't be modified or filtered. Unify them all to accept alphanumerics, underscores, spaces, hyphens, and dots. closes pulp#6456 Assisted-by: Claude-Opus-4.6 (Cursor)
4a5c471 to
35cdc41
Compare
mdellweg
approved these changes
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pulp_labels_validatorcrashed withTypeError: expected string or bytes-like objectwhen a label value was JSONnull, becausere.search()doesn't acceptNone. Skip the regex check forNonevalues since they are already accepted by theset_labelendpoint and HStoreField.pulp_labels_validator,SetLabelSerializer/UnsetLabelSerializer, andLabelFilterto consistently allow alphanumerics, underscores, spaces, hyphens, and dots. Previously, keys with spaces could be created but not modified viaset_label, and keys with hyphens were accepted byset_labelbut rejected on create.Test plan
pulp_labels_validatorcoveringNonevalues, empty strings, and keys with hyphens/dots/spaces.{"build_id": null}no longer returns a 500.closes #6593
closes #6456