datopian / ckanext-versioning

Deprecated. See https://github.com/datopian/ckanext-versions. ⏰ CKAN extension providing data versioning (metadata and files) based on git and github.
https://tech.datopian.com/versioning/
GNU Affero General Public License v3.0
7 stars 4 forks source link

Error when trying to edit a Version Info #31

Closed pdelboca closed 4 years ago

pdelboca commented 4 years ago

When editing a the first Version and using a github backend (so far it does not happen with filesystem backend) and error is raised:

image

Traceback (most recent call last):
  File "/home/pdelboca/Repos/ckanext-versioning/ckan/ckan/views/api.py", line 288, in action
    result = function(context, request_data)
  File "/home/pdelboca/Repos/ckanext-versioning/ckan/ckan/logic/__init__.py", line 464, in wrapped
    result = _action(context, data_dict, **kw)
  File "/home/pdelboca/Repos/ckanext-versioning/ckanext/versioning/logic/action.py", line 35, in dataset_tag_update
    tag, name, dataset_name_or_id = toolkit.get_or_bust(
  File "/home/pdelboca/Repos/ckanext-versioning/.venv/local/lib/python2.7/site-packages/metastore/backend/github/storage.py", line 163, in tag_update
    tag_info = self.tag_fetch(package_id, tag)
  File "/home/pdelboca/Repos/ckanext-versioning/.venv/local/lib/python2.7/site-packages/metastore/backend/github/storage.py", line 156, in tag_fetch
    return self._tag_ref_to_taginfo(package_id, repo, ref)
  File "/home/pdelboca/Repos/ckanext-versioning/.venv/local/lib/python2.7/site-packages/metastore/backend/github/storage.py", line 269, in _tag_ref_to_taginfo
    tag_obj = repo.get_git_tag(ref.object.sha)
AttributeError: 'NoneType' object has no attribute 'sha'

This is weird because it only happens when trying to edit the first Version of a Dataset, but it works correctly when trying to edit other versions of the same dataset.

How to reproduce:

shevron commented 4 years ago

To clarify, does it happen on the first version if you add additional versions? e.g.

Will this also fail?

shevron commented 4 years ago

Was able to reproduce this but only when editing the name, not the description. At some point, when I only had 1 tag, I could also edit the name. I'm not sure if this is intermittent or if a more complex set of preconditions is at play here.

shevron commented 4 years ago

I think this is a JS issue (!) that happens because somewhere the name of the current tag, only if it is looks like a decimal value ("1.0", "2.0") etc. gets converted to a float and then back into a string. The result is that the wrong tag name is sent in the action POST request:

Screen Shot 2020-07-26 at 12 42 04

I think that CKAN's way of using data-module-... variables for JS modules is to blame here, and we'll see if I can figure out a way to work around this. This may explain why this seemed "intermittent" earlier - because it only happens when version names look like a float (working to validate this hypothesis).

shevron commented 4 years ago

To be more exact: failure happens when the previous tag name is something that looks like a decimal, but that if converted to a string in JS will have different representation. Example:

shevron commented 4 years ago

Happens because CKAN will first try to JSON-parse module options, so anything that looks like a JSON float will be treated as such (see https://github.com/ckan/ckan/blob/master/ckan/public/base/javascript/module.js#L382).

Workaround is to JSON-encode tag names before putting them in the template. This can also avoid other issues e.g. if tag names contained some special characters.