-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
ModelSerializer dies on IntegerField with a max_length argument #2317
Comments
Simple way to test this. Make the following test model, which is perfectly valid django: class TestModel(models.Model):
hours = models.SmallIntegerField("hours", max_length=2, default=0) and then try to automatically serialize it with class TestSerializer(serializers.ModelSerializer):
class Meta:
model=TestModel |
Having noted that, we should still ensure that REST framework handles this case gracefully. |
Yes, I agree it makes little sense to use it. Maybe it's so form fields will get that argument and validate properly? Anyhow, there seems to be some apps out there in the wild that do use it. Although I haven't looked at the code yet, maybe a good general solution would be for these serializer fields to ignore arguments they don't recognize? That would also make this code much more future proof against changes in django. |
I've tried to fix this in PR #2345. Please give me comments on the fix, as it's my first contribution to this project. |
Sorry I've not been more helpful with detailing how to fix this the right way around, but pushed for time ATM. Will try to pick up with more advice in due course. Appreciate the work. |
Thanks for your input on this @hakanw - I've gone ahead and resolved this now as seemed simpler than passing back another review noting how to deal with it. |
@tomchristie aah, nice fix. I was messing around with another try but in fields.py, obviously not the right place. Thanks a lot! |
If an IntegerField, or PositiveIntegerField or any other number field has a
max_length
argument, then any serialization fails.Here's the stacktrace:
The text was updated successfully, but these errors were encountered: