Skip to content

Commit

Permalink
Don't validate the entire package when updating a single resource
Browse files Browse the repository at this point in the history
  • Loading branch information
ThrawnCA committed Jul 29, 2022
1 parent e442935 commit 636aab9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ckanext/validation/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def before_create(self, context, data_dict):
return self._process_schema_fields(data_dict)

resources_to_validate = {}
packages_to_skip = {}

def after_create(self, context, data_dict):

Expand Down Expand Up @@ -197,6 +198,15 @@ def before_update(self, context, current_resource, updated_resource):

updated_resource = self._process_schema_fields(updated_resource)

# the call originates from a resource API, so don't validate the entire package
package_id = updated_resource.get('package_id')
if not package_id:
existing_resource = t.get_action('resource_show')(
context={'ignore_auth': True}, data_dict={'id': updated_resource['id']})
if existing_resource:
package_id = existing_resource['package_id']
self.packages_to_skip[package_id] = True

if not get_update_mode_from_config() == u'async':
return updated_resource

Expand Down Expand Up @@ -242,6 +252,13 @@ def after_update(self, context, data_dict):
return

if is_dataset:
package_id = data_dict.get('id')
if self.packages_to_skip.pop(package_id, None) or context.get('save', False):
# Either we're updating an individual resource,
# or we're updating the package metadata via the web form;
# in both cases, we don't need to validate every resource.
return

for resource in data_dict.get(u'resources', []):
if resource[u'id'] in self.resources_to_validate:
# This is part of a resource_update call, it will be
Expand Down

0 comments on commit 636aab9

Please sign in to comment.