Descrição
Em packtools/sps/formats/oai_dc.py, a função xml_oai_dc_title lança AttributeError: 'NoneType' object has no attribute 'get' quando o XML de origem não possui <article-title>.
Causa
def xml_oai_dc_title(xml_oai_dc, xml_tree):
title = article_titles.ArticleTitles(xml_tree).article_title.get("text")
if title is not None:
el = ET.Element("{http://purl.org/dc/elements/1.1/}title")
el.text = title.strip()
xml_oai_dc.append(el)
ArticleTitles(xml_tree).article_title retorna None quando não há <article-title> no XML. O código chama .get("text") diretamente nesse retorno, sem checar se é None antes, causando o AttributeError.
Como reproduzir
.venv/bin/python -m pytest "tests/sps/formats/test_oai_dc.py::TestPipelineOaiDc::test_xml_oai_dc_without_title" -q
title = article_titles.ArticleTitles(xml_tree).article_title.get("text")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'
Sugestão de correção
def xml_oai_dc_title(xml_oai_dc, xml_tree):
article_title = article_titles.ArticleTitles(xml_tree).article_title
title = article_title.get("text") if article_title is not None else None
if title is not None:
el = ET.Element("{http://purl.org/dc/elements/1.1/}title")
el.text = title.strip()
xml_oai_dc.append(el)
Contexto
Identificado durante revisão/execução da suíte tests/sps/formats (conversor SciELO → OAI-DC). Pipelines que processam artigos sem <article-title> quebram completamente ao gerar o registro OAI-DC.
Descrição
Em
packtools/sps/formats/oai_dc.py, a funçãoxml_oai_dc_titlelançaAttributeError: 'NoneType' object has no attribute 'get'quando o XML de origem não possui<article-title>.Causa
ArticleTitles(xml_tree).article_titleretornaNonequando não há<article-title>no XML. O código chama.get("text")diretamente nesse retorno, sem checar se éNoneantes, causando oAttributeError.Como reproduzir
Sugestão de correção
Contexto
Identificado durante revisão/execução da suíte
tests/sps/formats(conversor SciELO → OAI-DC). Pipelines que processam artigos sem<article-title>quebram completamente ao gerar o registro OAI-DC.