Skip to content

Commit

Permalink
Address liteary form control field bug
Browse files Browse the repository at this point in the history
Why these changes are being introduced:

There is at least one MARC record that comes through
where control field 008 is not 34 characters, and therefore
was throwing an error when we attempt to grab the 33rd character.

How this addresses that need:
* If control field 008 is < 34 chars, return None for literary form

Side effects of this change:
* Transmogrifier runs for large swaths of files, e.g. full runs, will
not catastrophically fail for this single bug.
* This might suggest another layer of error handling to avoid full
run failure for a single record, will create at ticket for this.

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/TIMX-355
  • Loading branch information
ghukill committed Oct 31, 2024
1 parent e00c46e commit 9d99e85
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ line-length = 90
[tool.mypy]
disallow_untyped_calls = true
disallow_untyped_defs = true
exclude = ["tests/"]
exclude = ["tests/", "output/"]

[tool.pytest.ini_options]
log_level = "INFO"
Expand Down
7 changes: 7 additions & 0 deletions tests/sources/xml/test_marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,13 @@ def test_get_literary_form_transforms_correctly_if_char_positions_blank():
assert Marc.get_literary_form(source_record) is None


def test_get_literary_form_returns_none_if_control_field_too_short():
source_record = create_marc_source_record_stub(
control_field_insert='<controlfield tag="008">i_am_very_short</controlfield>',
)
assert Marc.get_literary_form(source_record) is None


def test_get_links_success():
source_record = create_marc_source_record_stub(
datafield_insert=(
Expand Down
5 changes: 5 additions & 0 deletions transmogrifier/sources/xml/marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,15 @@ def get_literary_form(cls, source_record: Tag) -> str | None:
and Leader/07 (Bibliographic level) contains code
a (Monographic component part), c (Collection), d (Subunit),
or m (Monograph).
If control field 008 is shorter than 34 characters, return None as we cannot
accurately determine.
"""
leader_field = cls._get_leader_field(source_record)
control_field = cls._get_control_field(source_record)
if leader_field[6] in "at" and leader_field[7] in "acdm":
if len(control_field) <= 33: # noqa: PLR2004
return None
if control_field[33] in "0se":
return "Nonfiction"
return "Fiction"
Expand Down

0 comments on commit 9d99e85

Please sign in to comment.