Skip to content
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 file uploads on localckan #213

Merged
merged 4 commits into from
Mar 12, 2024
Merged

Fix file uploads on localckan #213

merged 4 commits into from
Mar 12, 2024

Conversation

Zharktas
Copy link
Member

@Zharktas Zharktas commented Mar 8, 2024

Fixes #211

cgi.FieldStorage has been dropped from ckan since python 3 migration and its going away completely in python 3.13, this just replaces it with werkzeug FileStorage which ckan uses in the core as well.

@Zharktas
Copy link
Member Author

Zharktas commented Mar 8, 2024

@wardi are we really wanting to run tests on old ckan versions or should we just update them as well ?

@wardi
Copy link
Contributor

wardi commented Mar 8, 2024

We can drop tests on old ckans for sure

@JVickery-TBS
Copy link
Contributor

If using werkzeug now, do we need to add that into the requirements in this repo?

@wardi I was unable to find whatever fix we may have put in our fork of CKAN Core to fix this issue. Not sure if this was ever an issue with CKAN 2.9 or not? I will keep looking a bit more

@wardi
Copy link
Contributor

wardi commented Mar 8, 2024

@JVickery-TBS Not sure about requirements.

If you're using LocalCKAN then you need to have ckan in the same venv so we could assume werkzeug is there, and is the correct version for the ckan you're running.

If you're only using ckanapi for RemoteCKAN we don't need it.

If we did add a werkzeug requirement it would have to be an optional dependency: pip install ckanapi[localckan] or similar.

@JVickery-TBS
Copy link
Contributor

@wardi ahh okay makes sense. How does the RemoteCKAN send files? Just as a normal http POST?

AHA! I found it, and my original thought was right about the bool method of the cgi.FieldStorage being super broken and always returning False even if the object has data.

https://github.com/ckan/ckan/blob/2.9/ckan/lib/uploader.py#L263

bool(upload_field_storage)

if upload_field_storage is a cgi.FieldStorage object, this will always fail. https://bugs.python.org/issue19097 (python/cpython#63296)

Looks like the CloudStorage's plugin code does this:

if isinstance(upload_field_storage, (ALLOWED_UPLOAD_TYPES)):
            if len(upload_field_storage.filename):
            ......

So it is not doing bool on the cgi.FieldStorage. Not sure if we should do something like that upstream on the default CKAN uploaders?

@Zharktas
Copy link
Member Author

Remote CKAN uses HTTP api and that works even now, you just have to deal with api tokens which is not ideal if you are adding files to a ckan running locally. I'll update the workflows to run on supported ckan versions.

@Zharktas
Copy link
Member Author

Done. Cloudstorage and similar do checks on cgi.FieldStorage and werkzeug FileStorage as they try to support old CKAN versions, thats not really required any more as those versions aren't supported by the tech team either.

@wardi wardi merged commit 806ec26 into master Mar 12, 2024
10 checks passed
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.

Resource uploads fail on LocalCKAN
3 participants