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

Full URL of the resource stored in the DB #4382

Closed
tino097 opened this Issue Aug 1, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@tino097
Copy link
Member

tino097 commented Aug 1, 2018

CKAN Version if known (or site URL)

2.6+
Reported in #4070

Please describe the expected behaviour

When editing resource metadata, we should store the filename in the database, at resource table URL column.

Please describe the actual behaviour

When editing resource metadata, full URL is saved in the database

What steps can be taken to reproduce the issue?

1.Go to edit resource page
2.Save the changes

I've tested of this occurs on edit dataset and the issue is not reproducible.It occurs only on edit resource.

This occurs because we are generating the full url on reading the resource and it is stored as it in the DB on save

@amercader

This comment has been minimized.

Copy link
Member

amercader commented Aug 2, 2018

Here what's happening:

  • When creating the resource, the uploader stores just the file name in the url field
  • This is what gets stored in the database, by ckan.lib.dictization.model_save.resource_dict_save()

So far so good.

Now, when we add a new resource to the same dataset, or edit the existing resource:

  • resource_create and resource_update call package_show internally to update the whole dataset dict with the new/updated resource and pass it to package_update.
  • package_show (correctly) translates the single file name in url to a fully qualified URL so it can be displayed in the frontend or the API
  • But we are passing the dict with fully qualified URLs to package_update, which will store them on the database

We need to strip the full URL and store just the file name again when storing resources (only for resources where url_type=upload of course!). We can do that:

  1. At the model_save.resource_dict_save level
  2. At the default_update_resource_schema level (validation)

Note that the creation of the fully qualified URL is done at the same level of 1 in model_dictize.resource_dictize so perhaps it make sense to be consistent and do it there as well.

tino097 added a commit to tino097/ckan that referenced this issue Aug 3, 2018

@tino097 tino097 referenced this issue Aug 3, 2018

Merged

[#4382] strip full URL before saving to DB #4384

0 of 5 tasks complete

@wardi wardi closed this in #4384 Dec 4, 2018

wardi added a commit that referenced this issue Dec 4, 2018

Merge pull request #4384 from tino097/4382-full-url-stored
[#4382] strip full URL before saving to DB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment