Skip to content

Change the stream position after reading in validators #218

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

Merged
merged 1 commit into from
Apr 14, 2020

Conversation

jeromelebleu
Copy link

It ensures that the image's stream position is always at the start after running validators to prevent issues with further file reading - e.g. another validator which doesn't seek, or another form validation since seek(0) is called at the end.

This fixes an issue that I encounter using Wagtail and StdImageField with size validators. I always have the error Upload a valid image. The file you uploaded was either not an image or a corrupted image. for the image field. I presume to_python() is called on the field after the form validation. I didn't add a relevant test since it could require too much steps to encounter this issue.

Copy link
Owner

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @jeromelebleu another good catch. However, I am not sure if we shouldn't keep the seek(0) and to have it in both places. This will keep it working in case the value has the cursor set wrong from a previous routine. What do you think?

@jeromelebleu
Copy link
Author

I have asked myself this question a long time to finally think that it should already be at the start. But you're probably right, I will re-add it.

@codingjoe codingjoe merged commit 4c7194a into codingjoe:master Apr 14, 2020
@codingjoe
Copy link
Owner

Released in 5.1.1 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants