Fixes #1036: create_terms task crashes on cardinality validation during --check#1037
Open
devnull03 wants to merge 1 commit into
Open
Fixes #1036: create_terms task crashes on cardinality validation during --check#1037devnull03 wants to merge 1 commit into
devnull03 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Github issue or other discussion
#1036
What does this PR do?
This PR fixes a bug where Workbench crashes with an
UnboundLocalErrorwhen running--checkwith thecreate_termsorupdate_termstask if the CSV contains fields with values that exceed the field's cardinality limits.The
validate_csv_field_cardinality()function was only handlingcreateandupdatetasks when constructing warning messages for cardinality violations. When the task wascreate_termsorupdate_terms, themessagevariable was never assigned, causing a crash when the code attempted to print the warning.What changes were made?
Modified
workbench_utils.pyin thevalidate_csv_field_cardinality()function (lines ~7702-7778):ifstatement toeliffor theupdatetask condition (lines 7715 and 7742) to create proper conditional chainselifconditions forcreate_termstask that usesrow["term_name"]for identificationelifconditions forupdate_termstask that usesrow["term_id"]for identificationThese changes were made in two locations within the function - once for the "field allows 1 value but has multiple" scenario, and once for the "field allows N values but has more than N" scenario.
How to test / verify this PR?
Setup
create_termstask configuration with a CSV that has a field containing multiple delimited values (e.g.,value1;value2) where the Drupal field only allows a single value (cardinality = 1)Expected Behavior
Before this fix:
UnboundLocalError: cannot access local variable 'message' where it is not associated with a valueAfter this fix:
Warning: CSV field "field_name" in record with term name "Example Term" contains more values than the number allowed for that field (1). Workbench will add only the first value.--checkcompletes successfully without crashingVerification
Run
./workbench --config your_config.yml --checkand confirm it no longer crashes when CSV data violates field cardinality for taxonomy terms.Interested Parties
@mjordan @south-asian-canadian-digital-archive @sacda-ufv
Checklist
setup.py?