Skip to content

Fix TypeError: Object of type __proxy__ is not JSON serializable em task_migrate_and_publish_articles#930

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-json-serializable-error
Draft

Fix TypeError: Object of type __proxy__ is not JSON serializable em task_migrate_and_publish_articles#930
Copilot wants to merge 3 commits intomainfrom
copilot/fix-json-serializable-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

O que esse PR faz?

Corrige o TypeError: Object of type __proxy__ is not JSON serializable que interrompia a tarefa task_migrate_and_publish_articles. O objeto __proxy__ (gerado por gettext_lazy) era adicionado à lista de eventos da tarefa e não era tratado por sanitize_for_json, chegando inalterado ao psycopg2 durante o save().

Mudanças:

  • core/utils/sanitize.pysanitize_for_json agora preserva explicitamente tipos nativos JSON (int, float, bool, None) e converte qualquer outro tipo não-serializável para string via str(). O guarda de bool é essencial: sem ele, True/False seriam convertidos para as strings 'True'/'False' em vez dos literais JSON true/false.
# Antes: objetos __proxy__ passavam sem tratamento
return obj  # TypeError em runtime no psycopg2

# Depois: tipos nativos JSON preservados; tudo mais → str()
if isinstance(obj, (int, float, bool, type(None))):
    return obj
return str(obj)  # __proxy__, objetos customizados, etc.
  • proc/tests.py — 4 novos testes cobrindo lazy proxy isolado, em lista, em dict e objetos customizados não-serializáveis.

Onde a revisão poderia começar?

core/utils/sanitize.py — a mudança é cirúrgica (últimas 4 linhas da função sanitize_for_json), seguida dos novos testes em proc/tests.py.

Como este poderia ser testado manualmente?

Executar a tarefa task_migrate_and_publish_articles com os parâmetros journal_acron=rpe, collection_acron=rve, issue_folder=v25n1 e verificar que nenhum UnexpectedEvent do tipo TypeError é registrado ao final da execução.

Algum cenário de contexto que queira dar?

O fluxo de falha: add_event(_("..."))json.dumps falha → sanitize_for_json chamada mas não trata __proxy__self.save() falha no psycopg2. A correção cobre não apenas __proxy__, mas qualquer tipo não-serializável que possa chegar ao detail no futuro.

Screenshots

N/A

Quais são tickets relevantes?

[Migração de Artigos] Erro TypeError: Object of type proxy is not JSON serializable

Referências

Copilot AI and others added 2 commits April 23, 2026 17:27
Update sanitize_for_json to handle Django lazy translation objects
(__proxy__) and any other non-JSON-serializable types by converting
them to their string representation. Previously, the function only
handled str, dict, list/tuple and returned all other types unchanged,
causing JSON serialization to fail when Django's gettext_lazy strings
were added to task events.

Add tests covering the new behavior with lazy proxy objects.

Agent-Logs-Url: https://github.com/scieloorg/scms-upload/sessions/628ffd7d-9c8b-4b44-9f27-e162ad029666

Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix TypeError for JSON serialization in article migration Fix TypeError: Object of type __proxy__ is not JSON serializable em task_migrate_and_publish_articles Apr 23, 2026
Copilot AI requested a review from robertatakenaka April 23, 2026 17:30
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

Successfully merging this pull request may close these issues.

[Migração de Artigos] Erro TypeError: Object of type __proxy__ is not JSON serializable

2 participants