From 467cf5c1012c06c7e064d0f61e5710daecbcaf09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LeandroJata=C3=AD?= Date: Tue, 27 Jan 2026 17:02:15 -0300 Subject: [PATCH] Update sapl/materia/models.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- sapl/materia/models.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sapl/materia/models.py b/sapl/materia/models.py index 8c8d2db64..5e13f4ca7 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -441,12 +441,20 @@ class MateriaLegislativa(models.Model): else: numero = {'numero__max': 0} + # Converte o número preferido para inteiro, se possível + numero_preferido_int = None + if numero_preferido: + try: + numero_preferido_int = int(numero_preferido) + except (TypeError, ValueError): + numero_preferido_int = None + # Verifica se o número preferido está disponível - if numero_preferido and not MateriaLegislativa.objects.filter( + if numero_preferido_int is not None and not MateriaLegislativa.objects.filter( tipo=tipo, ano=ano, - numero=numero_preferido).exists(): - return int(numero_preferido), ano + numero=numero_preferido_int).exists(): + return numero_preferido_int, ano # Retorna o próximo número sequencial max_numero = numero['numero__max']