[Django] #35018: Invalid SQL for GeneratedField on Oracle

5 views
Skip to first unread message

Django

unread,
Dec 6, 2023, 3:39:56 AM12/6/23
to django-...@googlegroups.com
#35018: Invalid SQL for GeneratedField on Oracle
-------------------------------------+-------------------------------------
Reporter: Václav | Owner: nobody
Řehák |
Type: Bug | Status: new
Component: Database | Version: 5.0
layer (models, ORM) |
Severity: Normal | Keywords: oracle
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I'm not sure this is actual bug or I am doing something wrong (please
point me to the doc if I missed one).

I am trying `GeneratedField` on Django 5.0 in a project running on Oracle
Database 19c Enterprise Edition, Version 19.18.0.0.0. My real use case is
bit more complicated so made up a simpler one - I have
`ts_password_changed` as `DateTimeField(blank=True, null=True)` and I'm
trying to add generated boolean field:


{{{
is_password_changed = GeneratedField(
expression=ExpressionWrapper(Q(ts_password_changed__isnull=False),
output_field=models.BooleanField()),
output_field=models.BooleanField(),
db_persist=False
)
}}}

The generated migration SQL looks like this:


{{{
ALTER TABLE "CORE_USER" ADD "IS_PASSWORD_CHANGED" NUMBER(1) GENERATED
ALWAYS AS ("TS_PASSWORD_CHANGED" IS NOT NULL) VIRTUAL;
}}}
and Oracle refuses it with

{{{
ORA-54016: Invalid column expression was specified, Position 81
}}}

However, it works when I modify the query to


{{{
ALTER TABLE "CORE_USER" ADD "IS_PASSWORD_CHANGED" NUMBER(1) GENERATED
ALWAYS AS (CASE WHEN "TS_PASSWORD_CHANGED" IS NOT NULL THEN 1 ELSE 0 END)
VIRTUAL;
}}}
which is probably what Django should be generating.

--
Ticket URL: <https://code.djangoproject.com/ticket/35018>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages