-
Notifications
You must be signed in to change notification settings - Fork 29
[FIX] base_bg: Add priority usage to enqueue and context serialization to avoid errors #315
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
Conversation
…n to avoid errors
3f5a6a7 to
b23677c
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
Este PR corrige un problema en el módulo base_bg al agregar soporte para el parámetro priority en el encolado de trabajos y filtrar valores no serializables del contexto para evitar errores de serialización JSON.
Cambios principales:
- Extracción y uso del parámetro
priorityenbg_enqueue(con valor por defecto 10) - Filtrado del contexto para incluir solo valores serializables antes de guardar en
context_json - Nuevo método helper
is_serializableque verifica si un valor puede ser serializado a JSON
| """ | ||
| Método que verifica si un valor es serializable. | ||
| :param self: Modelo ai.utils |
Copilot
AI
Dec 10, 2025
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.
El parámetro :param self: Modelo ai.utils en el docstring es incorrecto. Debería ser base.bg en lugar de ai.utils, que es el modelo real donde se define este método.
| :param self: Modelo ai.utils | |
| :param self: base.bg |
| :return: A display notification | ||
| """ | ||
| priority = kwargs.pop("priority", 10) |
Copilot
AI
Dec 10, 2025
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.
Se ha agregado soporte para el parámetro priority (línea 28) pero falta documentarlo en el docstring del método. Considera agregar :param priority: Prioridad del trabajo (valor menor = mayor prioridad), default: 10 en la sección "Special kwargs" del docstring.
| def is_serializable(self, value: Any) -> bool: | ||
| """ | ||
| Método que verifica si un valor es serializable. | ||
| :param self: Modelo ai.utils | ||
| :param value: Valor a verificar | ||
| """ | ||
| try: | ||
| json.dumps(value) | ||
| return True | ||
| except Exception: | ||
| return False |
Copilot
AI
Dec 10, 2025
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.
La nueva funcionalidad de is_serializable y el filtrado de contexto (líneas 30, 73-84) carecen de cobertura de tests. El repositorio tiene tests comprehensivos en base_bg/tests/test_bg_job.py, por lo que deberían agregarse casos de prueba que verifiquen:
- Que el método
is_serializableretorne True para valores serializables (dict, list, str, int, etc.) - Que retorne False para valores no serializables (objetos Odoo, recordsets, etc.)
- Que
bg_enqueuefiltre correctamente el contexto, removiendo valores no serializables
| priority = kwargs.pop("priority", 10) | ||
| max_retries = kwargs.pop("max_retries", 3) | ||
| context = {k: v for k, v in self.env.context.items() if self.is_serializable(v)} | ||
| name = kwargs.pop("name", f"{self._name}.{method}") | ||
| job_vals = { | ||
| "name": name, | ||
| "model": self._name, | ||
| "method": method, | ||
| "priority": priority, |
Copilot
AI
Dec 10, 2025
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.
Se están realizando cambios en el modelo base.bg (adición de campo priority en job_vals y lógica de filtrado de contexto), pero el __manifest__.py no incrementa la versión. Según las guías del proyecto, cuando se modifican modelos, vistas, seguridad o datos, se debe hacer un bump de versión. Se recomienda incrementar de 19.0.1.0.0 a 19.0.1.0.1.
| try: | ||
| json.dumps(value) | ||
| return True | ||
| except Exception: |
Copilot
AI
Dec 10, 2025
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.
El uso de una cláusula except Exception genérica puede ocultar errores inesperados. Se recomienda capturar excepciones específicas como TypeError y ValueError, que son las que lanza json.dumps cuando encuentra valores no serializables. Ejemplo:
except (TypeError, ValueError):
return False| except Exception: | |
| except (TypeError, ValueError): |
|
@roboadhoc r+ |

No description provided.