Commit e4457efb authored by Marko Kuder's avatar Marko Kuder
Browse files

fix wrong resources being overwritten on upload

- while using downloadall, the uploaded bulk package was sometimes not stored in the newly created resource but another one, because it was retrieved at the start of the resource list, not at the end as expected
parent cc828322
......@@ -201,6 +201,14 @@ def opsi_action_resource_create(context, data_dict):
# way to generate a full URL here (e.g. by generating an ID for the resource beforehand) to avoid changing between
# the filename and a full URL later on after archiver processing etc.
# Gather IDs of existing resources to compare after when getting the new resource ID for the uploader.
# The upstream implementation just uses the last resource but it seems that it is not guaranteed that the
# new resource is returned as the last (observed when integrating the downloadall plugin which could
# overwrite other resource files in some cases) - an uploaded "documentation" type was usually put first.
old_resource_ids = []
for resource in pkg_dict['resources']:
......@@ -224,17 +232,21 @@ def opsi_action_resource_create(context, data_dict):
mime = magic.from_buffer(, mime=True), os.SEEK_SET)
raise ValidationError({'upload': ['Datotek formata '+mime+' ni dovoljeno nalagati na portal OPSI.']})
new_resource_id = context['package'].resources[-1].id #fallback to upstream system of just using last resource
for resource in context['package'].resources:
if not in old_resource_ids:
new_resource_id =
## Get out resource_id resource from model as it will not appear in
## package_show until after commit
## Run package show again to get out actual last_resource
pkg_dict = _get_action('package_show')(context, {'id': package_id})
resource = pkg_dict['resources'][-1]
## Run resource show get out actual last resource
resource = _get_action('resource_show')(context, {'id': new_resource_id})
for plugin in plugins.PluginImplementations(plugins.IResourceController):
plugin.after_create(context, resource)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment