-
Notifications
You must be signed in to change notification settings - Fork 33
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
Fix Upload Field Condition #96
Open
JVickery-TBS
wants to merge
3
commits into
ckan:master
Choose a base branch
from
JVickery-TBS:fix/new-upload
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be an
and
. We want to check that the object exists and contains a non-blank fileThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ThrawnCA the new
getattr
default toFalse
, so do not need to check for upload object, if it is not an object or does not have those attributes, it will beFalse
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JVickery-TBS which versions of ckan are we testing the validation plugin against?
i see https://github.com/ckan/ckanext-validation/blob/master/.github/workflows/test.yml 2.9 only here
we have bumped ours to do 2.9 and 2.10: https://github.com/qld-gov-au/ckanext-validation/blob/master/.github/workflows/test.yml
and we have started introducing 'master/head' testing (allowing failures) so we know what's coming + allowing 'forks' to be tested again (i.e. qld-gov-au ckan delta that has the altered upload interface to allow 'download' in once nice place): https://github.com/ckan/ckanext-xloader/blob/master/.github/workflows/test.yml#L26
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the ckan/ckanext-validation is only 2.9 as it does not have 2.10+ support in this repo yet? That I know of at least. Unless if you added it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that's why we need
and
, to make thatFalse
take effect and override theTrue
resulting from the object's presence.If the object is present, but lacks both
file
andfilename
, then this will proceed when it shouldn't.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ThrawnCA right okay. Sorry I kind of forgot what this fix was for. I cannot test for the
updated_resource.get(u'upload') AND
becauseupdated_resource.get(u'upload')
is going to be false if it is acgi.FieldStorage
object. Here is the issue in cgi: https://bugs.python.org/issue19097So that is why we have to just check for the filename or file.
I guess we could check the class type of
updated_resource.get(u'upload')
? and if it is an instance ofFieldStorage
then check for the filename or file?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ThrawnCA okay, I modified the condition now, so we check for
cgi.FieldStorage
and then check if thefilename
orfile
attribute is there. Put an inline comment regarding the bug we are working around here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm...that is an inconvenient bug indeed, but the current logic still isn't right. We still proceed any time
upload
is truthy, regardless of thefilename
andfile
fields, which is a problem when dealing with Werkzeug storage containing no data.What about something like "(
upload
is either truthy or an instance ofcgi.FieldStorage
) and (eitherfile
orfilename
is present)"?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, that bug says it's fixed on Python 3, which is now the only supported version for this plugin. Do we still need to worry about it?