Skip to content

Bug: xml_oai_dc_title lança AttributeError quando o artigo não possui article-title #1215

@Rossi-Luciano

Description

@Rossi-Luciano

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions