Skip to content
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

METSRW tries to call property for a non-existent object #39

Closed
peterVG opened this issue Jul 16, 2020 · 2 comments
Closed

METSRW tries to call property for a non-existent object #39

peterVG opened this issue Jul 16, 2020 · 2 comments

Comments

@peterVG
Copy link
Member

peterVG commented Jul 16, 2020

METSRW tries to call a property for a non-existent object (inside a function that creates a new AMDSec by parsing the root element).

See https://github.com/artefactual-labs/mets-reader-writer/blob/master/metsrw/metadata.py#L94-L103

The error that is raised:

[2020-07-15 15:57:58,502: ERROR/ForkPoolWorker-4] Task AIPscan.Aggregator.tasks.get_mets[a24ce0ce-6e25-40d5-b117-ce5435944741] raised unexpected: AttributeError("'NoneType' object has no attribute 'tag'")
Traceback (most recent call last):
  File "/Users/peter/Development/AIPscan/venv/lib/python3.7/site-packages/celery/app/trace.py", line 412, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/Users/peter/Development/AIPscan/flask_celery.py", line 18, in __call__
    return TaskBase.__call__(self, *args, **kwargs)
  File "/Users/peter/Development/AIPscan/venv/lib/python3.7/site-packages/celery/app/trace.py", line 704, in __protected_call__
    return self.run(*args, **kwargs)
  File "/Users/peter/Development/AIPscan/AIPscan/Aggregator/tasks.py", line 271, in get_mets
    mets = metsrw.METSDocument.fromfile(downloadFile)
  File "/Users/peter/Development/AIPscan/venv/lib/python3.7/site-packages/metsrw/mets.py", line 593, in fromfile
    return cls.fromtree(etree.parse(path, parser=parser))
  File "/Users/peter/Development/AIPscan/venv/lib/python3.7/site-packages/metsrw/mets.py", line 617, in fromtree
    mets._parse_tree(tree)
  File "/Users/peter/Development/AIPscan/venv/lib/python3.7/site-packages/metsrw/mets.py", line 543, in _parse_tree
    tree, structMap, normative_parent_elem=normative_struct_map
  File "/Users/peter/Development/AIPscan/venv/lib/python3.7/site-packages/metsrw/mets.py", line 367, in _parse_tree_structmap
    tree, elem, normative_parent_elem=normative_elem
  File "/Users/peter/Development/AIPscan/venv/lib/python3.7/site-packages/metsrw/mets.py", line 371, in _parse_tree_structmap
    self._add_amdsecs_to_fs_entry(elem.get("ADMID"), fs_entry, tree)
  File "/Users/peter/Development/AIPscan/venv/lib/python3.7/site-packages/metsrw/mets.py", line 515, in _add_amdsecs_to_fs_entry
    amdsec = metadata.AMDSec.parse(amdsec_elem)
  File "/Users/peter/Development/AIPscan/venv/lib/python3.7/site-packages/metsrw/metadata.py", line 94, in parse
    if root.tag != utils.lxmlns("mets") + "amdSec":
AttributeError: 'NoneType' object has no attribute 'tag'

The work around for now is to patch METSRW/metadata.py with the following code:

    @classmethod
    def parse(cls, root):
        """
        Create a new AMDSec by parsing root.

        :param root: Element or ElementTree to be parsed into an object.
        """
        if root:
            if root.tag != utils.lxmlns("mets") + "amdSec":
                raise exceptions.ParseError(
                    "AMDSec can only parse amdSec elements with METS namespace."
                )
            section_id = root.get("ID")
            subsections = []
            for child in root:
                subsection = SubSection.parse(child)
                subsections.append(subsection)
            return cls(section_id, subsections)
        else:
            return
@ross-spencer
Copy link
Contributor

Related to archivematica/Issues#1129

@ross-spencer
Copy link
Contributor

Given the related issue and this ticket here: #47 I feel we're doing enough to handle this in AIPscan now, and we can close this in favor of reporting the AIP errors summary. We will need to track metsrw and AIP changes upstream but this one might just resolve itself once Archivematica outputs the METS correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants