Fix TypeError: Object of type __proxy__ is not JSON serializable em task_migrate_and_publish_articles#930
Draft
Fix TypeError: Object of type __proxy__ is not JSON serializable em task_migrate_and_publish_articles#930
Conversation
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>
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
O que esse PR faz?
Corrige o
TypeError: Object of type __proxy__ is not JSON serializableque interrompia a tarefatask_migrate_and_publish_articles. O objeto__proxy__(gerado porgettext_lazy) era adicionado à lista de eventos da tarefa e não era tratado porsanitize_for_json, chegando inalterado ao psycopg2 durante osave().Mudanças:
core/utils/sanitize.py—sanitize_for_jsonagora preserva explicitamente tipos nativos JSON (int,float,bool,None) e converte qualquer outro tipo não-serializável para string viastr(). O guarda deboolé essencial: sem ele,True/Falseseriam convertidos para as strings'True'/'False'em vez dos literais JSONtrue/false.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çãosanitize_for_json), seguida dos novos testes emproc/tests.py.Como este poderia ser testado manualmente?
Executar a tarefa
task_migrate_and_publish_articlescom os parâmetrosjournal_acron=rpe,collection_acron=rve,issue_folder=v25n1e verificar que nenhumUnexpectedEventdo tipoTypeErroré registrado ao final da execução.Algum cenário de contexto que queira dar?
O fluxo de falha:
add_event(_("..."))→json.dumpsfalha →sanitize_for_jsonchamada 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 aodetailno 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