Fix BuildError when last_issue.url_segment is None on journal detail page#429
Fix BuildError when last_issue.url_segment is None on journal detail page#429
Conversation
Use fix_journal_last_issue() to populate url_segment in journal_detail and about_journal views. Add defensive template guards to check last_issue.url_segment before building URLs. Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes a recurring Flask/Werkzeug BuildError on the public journal detail page (/j/<acron>/) when journal.last_issue exists but its url_segment is None (not populated in the SPF flow), ensuring links to the latest issue can be built safely.
Changes:
- Public views now call
utils.fix_journal_last_issue(journal)to derive/filllast_issue.url_segmentwhen missing. journal/detail.htmlnow guards rendering of “last issue” blocks onlast_issue.url_segmentand fixes an invalid template variable (latest_issue.cover_url→last_issue.cover_url).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
opac/webapp/main/views.py |
Backfills last_issue.url_segment for public journal pages by reusing existing helper logic. |
opac/webapp/templates/journal/detail.html |
Prevents url_for from being called without url_seg_issue and fixes cover image binding to the correct context variable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| latest_issue = utils.fix_journal_last_issue(journal) | ||
|
|
||
| if latest_issue: | ||
| latest_issue_legend = descriptive_short_format( |
There was a problem hiding this comment.
Add a regression test for the scenario this change fixes: a Journal with last_issue present but last_issue.url_segment is None should render /j/<acron>/ (and /journal/<acron>/about/) without raising BuildError, and should generate a valid issue_toc link using the derived segment. There are already integration tests for main.journal_detail, so covering this edge case will prevent the error from reappearing.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
O que esse PR faz?
Corrige o
BuildErrorrecorrente em/j/<acron>/quandolast_issueexiste masurl_segmentéNone— situação que ocorre no fluxo SPF ondeLastIssue.url_segmentnão é preenchido ao registrar issues.Duas correções:
opac/webapp/main/views.py: Usautils.fix_journal_last_issue(journal)(já existia para admin views) emjournal_detail()eabout_journal()para construirurl_segmenta partir de year/volume/number quando ausenteopac/webapp/templates/journal/detail.html: Guarda defensiva{% if last_issue and last_issue.url_segment %}em ambos os blocos, e corrige referências alatest_issue.cover_url(variável inexistente no contexto) paralast_issue.cover_urlOnde a revisão poderia começar?
opac/webapp/main/views.pylinha 512 — a chamada afix_journal_last_issue().Como este poderia ser testado manualmente?
last_issuecujourl_segmentsejaNone/j/<acron>/BuildErrorurl_segmentexiste, os links para o último número continuam funcionandoAlgum cenário de contexto que queira dar?
A função
fix_journal_last_issue()emwebapp/utils/utils.pyjá tratava exatamente este caso e já era usada emadmin/views.py:1004, mas não era chamada nas views públicas. O docstring da própria função documenta que o SPF não preencheurl_segment.Screenshots
N/A — correção de erro server-side.
Quais são tickets relevantes?
Erro recorrente relacionado com url_segment.
Referências
opac/webapp/utils/utils.py:610-627—fix_journal_last_issue()opac/webapp/admin/views.py:1004— uso existente da mesma funçãoWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.twitter.com/home/REDACTED/.local/bin/flask flask --app opac.app test rese�� ng/Offset.o(dns block)/home/REDACTED/.local/bin/flask flask --app opac.app test rev-��(dns block)/home/REDACTED/.local/bin/flask flask --app opac.app test --pid-file /run/containerd/io.containerd.runtime.v2.task/moby/cd1c72e168274290c2e76f74295e1618a5a8f39cd3d0a620118ac01a901b8e87/init.pid cd1c72e168274290c2e76f74295e1618a5a8f39cd3d0a620118ac01a901b8e87 u/13/cc1 unset hon3.12 k/_temp/copilot---noprofile u/13/cc1 --li�� ng/QuantPngQuant.o --keep-system-libs de in.so hon3.12(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>Erro recorrente relaciondo com url_segment</issue_title>
<issue_description>### Descrição do problema
Recentemente está ocorrendo um erro relacionado com o último issue do periódico.
Passos para reproduzir o problema
Comportamento esperado
ausência de erro
Screenshots ou vídeos
n/a
Ambiente utilizado
n/a
</i...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.