-
Notifications
You must be signed in to change notification settings - Fork 10
Melhorias no carregamento de Issues para completar corretamente seções dos artigos #1260
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
Melhorias no carregamento de Issues para completar corretamente seções dos artigos #1260
Conversation
- Restringe django-otp < 1.2.0 - Resolve problema com VerifyUserPermissionsMiddleware
- Remove registros órfãos (sem url e sem data) antes da consulta - Trata MultipleObjectsReturned retornando o registro mais recente
- Adiciona fallback para lista vazia em sections_data - Adiciona fallback para lista vazia em bibliographic_strip
- Restringe django-otp < 1.2.0 - Resolve problema com VerifyUserPermissionsMiddleware
complete_am_issue: - Adiciona validações e detalhes para debug get_issue_data_from_am_issue: - Melhora tratamento de am_issue.data ausente - Extrai journal_pid do pid ao invés de am_data - Adiciona detalhes de debug nas exceções create_issue_from_am_issue: - Extrai lógica de carregamento para funções dedicadas Novas funções: - _extract_field: extração genérica com prioridade de fontes - load_issue_sections: carrega sections com tratamento de erros - load_issue_titles: carrega títulos com tratamento de erros - load_bibliographic_strips: carrega strips com tratamento de erros
task_update_issues_from_amissue: - Suporta filtros por collection, journal_pid, status, datas - Suporta filtros por year, volume, number, supplement - Opção force_update para atualizar Issues existentes - Opção only_without_new_record para processar apenas pendentes - Remove AMIssue órfãos antes do processamento - Retorna estatísticas detalhadas de processamento - Tratamento individual de erros por registro
- Carrega sections do AMIssue se table_of_contents estiver vazio - Usa TableOfContents.get_items_by_title para busca padronizada - Corrige import de load_issue_sections para issue_utils - Move verificação de exists() antes do loop de append
5bca402 to
32647fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR improves the robustness of Issue loading and synchronization from ArticleMeta, adds a batch task to update Issues from AMIssue, and tightens handling of duplicate/legacy records.
Changes:
- Adds stricter legacy record retrieval in
BaseLegacyRecord.getandIssue.get, including duplicate resolution and auto-filling of computed fields (issue_folder,issue_pid_suffix,order). - Refactors the ArticleMeta Issue loader into reusable helpers (
get_issue_data_from_am_issue,load_issue_sections,load_issue_titles,load_bibliographic_strips) and introducestask_update_issues_from_amissuefor bulk updates. - Enhances TOC section lookup and ArticleMeta-backed section loading in XML SPS article import, and adds a compatibility pin for
django-otpto work withwagtail_2fa.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| requirements/base.txt | Adds django-otp<1.2.0 constraint to maintain compatibility with wagtail_2fa. |
| core/models.py | Updates BaseLegacyRecord.get to clean orphan records and resolve duplicates by returning the most recently updated record. |
| issue/models.py | Ensures Issue.short_identification and Issue.get auto-generate missing computed fields and adds TableOfContents.get_items_by_title for consistent TOC lookups. |
| issue/articlemeta/issue_utils.py | Makes extract_data_from_harvested_data robust to missing sections_data / bibliographic_strip by defaulting to empty collections. |
| issue/articlemeta/loader.py | Strengthens complete_am_issue and get_issue_data_from_am_issue error reporting and factors out reusable load_issue_* helpers for sections, titles, and bibliographic strips. |
| issue/tasks.py | Introduces task_update_issues_from_amissue to bulk-create/update Issue records from AMIssue with rich filtering and per-item error tracking. |
| article/sources/xmlsps.py | Integrates AMIssue-backed TOC sections into get_or_create_toc_sections and switches to TableOfContents.get_items_by_title for normalized TOC section resolution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from issue.models import Issue, TableOfContents, AMIssue | ||
| from issue.articlemeta.loader import load_issue_sections |
Copilot
AI
Jan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load_issue_sections is imported from issue.articlemeta.issue_utils, but the function is actually defined in issue.articlemeta.loader; as written this import will raise ImportError at module import time and break any code path that loads article.sources.xmlsps.
To fix this, adjust the import to pull load_issue_sections from the correct module (issue.articlemeta.loader).
| if issue.table_of_contents is None: | ||
| raise cls.DoesNotExist("TableOfContents.get_items_by_title requires valid issue") |
Copilot
AI
Jan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if issue.table_of_contents is None: will never trigger because table_of_contents is a reverse related manager on Issue and is never None, even when there are no TOC records; this makes the branch (and its DoesNotExist message about a "valid issue") effectively dead code and may confuse future maintainers.
If you want to guard on the presence of TOC entries, consider checking for emptiness (e.g. if not issue.table_of_contents.exists():) or simply dropping this check and relying on the query/filter itself.
| if issue.table_of_contents is None: | |
| raise cls.DoesNotExist("TableOfContents.get_items_by_title requires valid issue") |
| except Exception: | ||
| pass |
Copilot
AI
Jan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'except' clause does nothing but pass and there is no explanatory comment.
| except Exception: | |
| pass | |
| except Exception as exc: | |
| logging.getLogger(__name__).warning( | |
| "Failed to delete legacy records with null url and data in %s.get: %s", | |
| cls.__name__, | |
| exc, | |
| ) |
| # Limpar AMIssue órfãos (sem data e sem URL) | ||
| AMIssue.objects.filter(data__isnull=True, url__isnull=True).delete() | ||
| except Exception: | ||
| pass |
Copilot
AI
Jan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'except' clause does nothing but pass and there is no explanatory comment.
| pass | |
| logging.exception("Failed to delete orphan AMIssue records (data__isnull=True, url__isnull=True)") |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Resumo
Este PR implementa melhorias significativas no processo de carregamento de Issues a partir do ArticleMeta, adiciona uma nova task para atualização em lote, e corrige problemas de robustez nos modelos.
Mudanças
Core
MultipleObjectsReturnedIssue
Models
issue_folderautomaticamente se ausenteissue_folder,issue_pid_suffix,order)get_items_by_titlepara busca padronizada por títuloArticleMeta Loader
complete_am_issueeget_issue_data_from_am_issuecom melhor tratamento de erros e detalhes para debug_extract_field: extração genérica com prioridade de fontesload_issue_sections: carrega sections com tratamento de errosload_issue_titles: carrega títulos com tratamento de errosload_bibliographic_strips: carrega strips com tratamento de errosIssue Utils
Noneemsections_dataebibliographic_stripTasks
task_update_issues_from_amissue: Atualização em lote de Issues com suporte a múltiplos filtros (collection, journal, status, datas, volume, número, etc.)Article
Sources (xmlsps)
get_or_create_toc_sectionspara carregar sections do AMIssue quando necessárioTableOfContents.get_items_by_titlepara busca padronizadaDependencies
django-otp < 1.2.0para compatibilidade comwagtail_2fa.middleware.VerifyUserPermissionsMiddlewareCommits
Testes
task_update_issues_from_amissuecom diferentes filtros