#33769: F() expressions - OperationalError
-------------------------------+------------------------------------
Reporter: Pablo | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 3.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Comment (by Pablo):
I'm sorry, but I don't understand the exact way to Bisecting a regression.
I leave the SQL statement with the original models to avoid making any
changes (I have deleted some non-transcendent fields for this case) that
would allow you to see a possible explanation. It's funny but the two SQL
statements are the same, so it could be that the problem is how it
resolves the name of the table, since it concatenates the name of its
primary key?
Seasson -> Temporada
WorkShift -> Turno
season__chief_tipes -> jefatura_tipos_turno_publicos
AppName -> turnos
Original error
{{{
OperationalError at /
no such table: turnos_temporada_jefatura_tipos_turno_publicos.tipoturno_id
}}}
The models.
{{{
class Temporada(models.Model):
jefatura_tipos_turno_publicos =
models.ManyToManyField('turnos.TipoTurno',
related_name='turnos_temporadas_jefatura',
verbose_name=_('Jefatura - Tipos de turno públicos'),
blank=True)
class Turno(models.Model):
temporada = models.ForeignKey(Temporada, on_delete=models.CASCADE)
tipo = models.ForeignKey('TipoTurno', null=True,
on_delete=models.PROTECT)
fecha_inicio = models.DateTimeField(_('Inicio turno'))
fecha_fin = models.DateTimeField(_('Fin turno'))
class TipoTurno(models.Model):
nombre = models.CharField(_('Nombre'), max_length=30)
}}}
The Queryset
{{{
turnos_jefatura = Turno.objects.filter(temporada__in=temporadas,
tipo__in=F('temporada__jefatura_tipos_turno_publicos'),
fecha_fin__gte=hoy
).filter(
Q(fecha_inicio__lte=hoy) | Q(fecha_inicio__lte=hoy +
datetime.timedelta(hours=12))
)
}}}
Django 2.2 SQL
{{{
SELECT "turnos_turno"."id",
"turnos_turno"."temporada_id",
"turnos_turno"."tipo_id",
"turnos_turno"."fecha_inicio",
"turnos_turno"."fecha_fin",
FROM "turnos_turno"
INNER JOIN "turnos_temporada"
ON ("turnos_turno"."temporada_id" =
"turnos_temporada"."id")
INNER JOIN "turnos_temporada_jefatura_tipos_turno_publicos"
ON ("turnos_temporada"."id" =
"turnos_temporada_jefatura_tipos_turno_publicos"."temporada_id")
WHERE ("turnos_turno"."fecha_fin" >= '''2022-06-06 17:18:46.405382''' AND
"turnos_turno"."temporada_id" IN (SELECT V0."id"
FROM "turnos_temporada" V0
LEFT OUTER JOIN
"turnos_temporada_jefatura_parques_afectacion" V1
ON
(V0."id" = V1."temporada_id")
WHERE (V0."activo" = 'True' AND
V0."es_jefatura" = 'True' AND
V0."fecha_fin" >=
'''2022-06-06''' AND
V0."fecha_inicio" <=
'''2022-06-06''' AND
(V1."parque_id" IN (SELECT
DISTINCT U0."id"
FROM
"parques_parque" U0
WHERE
U0."id" IN
(...)) OR
V1."parque_id" IS NULL)))
AND
"turnos_turno"."tipo_id" IN
("turnos_temporada_jefatura_tipos_turno_publicos"."tipoturno_id") AND
("turnos_turno"."fecha_inicio" <= '''2022-06-06 17:18:46.405382'''
OR
"turnos_turno"."fecha_inicio" <= '''2022-06-07
05:18:46.405382'''))
}}}
Django 3.2 SQL
{{{
SELECT "turnos_turno"."id",
"turnos_turno"."temporada_id",
"turnos_turno"."tipo_id",
"turnos_turno"."fecha_inicio",
"turnos_turno"."fecha_fin",
FROM "turnos_turno"
INNER JOIN "turnos_temporada"
ON ("turnos_turno"."temporada_id" =
"turnos_temporada"."id")
INNER JOIN "turnos_temporada_jefatura_tipos_turno_publicos"
ON ("turnos_temporada"."id" =
"turnos_temporada_jefatura_tipos_turno_publicos"."temporada_id")
WHERE ("turnos_turno"."fecha_fin" >= '''2022-06-07 09:58:33.644086''' AND
"turnos_turno"."temporada_id" IN (SELECT V0."id"
FROM "turnos_temporada" V0
LEFT OUTER JOIN
"turnos_temporada_jefatura_parques_afectacion" V1
ON
(V0."id" = V1."temporada_id")
WHERE (V0."activo" AND
V0."es_jefatura" AND
V0."fecha_fin" >=
'''2022-06-07''' AND
V0."fecha_inicio" <=
'''2022-06-07''' AND
(V1."parque_id" IN (SELECT
DISTINCT U0."id"
FROM
"parques_parque" U0
WHERE
U0."id" IN
(...)) OR
V1."parque_id" IS NULL)))
AND
"turnos_turno"."tipo_id" IN
"turnos_temporada_jefatura_tipos_turno_publicos"."tipoturno_id" AND (
"turnos_turno"."fecha_inicio" <= '''2022-06-07 09:58:33.644086'''
OR
"turnos_turno"."fecha_inicio" <= '''2022-06-07 21:58:33.644086'''))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33769#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701813d56bfd5-cbb045b3-6515-4ddf-bc15-bfe3ec797b15-000000%40eu-central-1.amazonses.com.