Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Excluding required fields in Query Parameter fields#1214

Unanswered
jaimeres asked this question inQ&A
Discussion options

If, when creating a record, I use the 'QueryParameterValidationFilter fields', the excluded fields are not validated. Consider the following example, where 'name' is not validated because it is not included in fields.

class Product(models.Model):    name = models.CharField(max_length=100)    field1 = models.CharField(max_length=100, blank=True)    field2 = models.CharField(max_length=100, blank=True)Post uri.fields[type]=field1,field2
You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Thanks for the heads-up. A very good find.

Some clarification. The QueryParameterValidationFilter only validates the query parameters itself. It is allowed to use sparse fields with POST request as perspec. However, theSparseFieldsetsMixin which is in charge of interpreting the fields parameter drops the fields of the serializer when parsing and rendering. It should not do it when parsing which is a bug and leads to your explained behavior. It does not validate exclude fields, but it also drops that field from the input data altogether when saving it.

Looking at the code, the mixin should instead of overwriting__init__ overwrite_readable_fields property. A PR is welcome.

You must be logged in to vote
1 reply
@sliverc
Comment options

As this is a bug, I have created an issue#1216, so hopefully someone can pick it up and implement it.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@jaimeres@sliverc

[8]ページ先頭

©2009-2025 Movatter.jp