#33358: Adding duration field with default <24h raises an error in oracle
-------------------------------------+-------------------------------------
Reporter: Marcello | Owner: nobody
Dalponte |
Type: Bug | Status: new
Component: Database | Version: 3.1
layer (models, ORM) | Keywords:
Severity: Normal | durationfield,oracle
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
== BUG DESCRIPTION
When adding a DurationField with a default which is smaller than 24h
{{{#!python
class Scheduler(models.Model):
delay = models.DurationField(default=timedelta(minutes=5))
}}}
I get this error with the oracle backend
{{{
ORA-01735: invalid ALTER TABLE option
}}}
----
== INVESTIGATION
I dug into the issue and I found that the reason why the query errors is
because the query generated by the migration app is
{{{#!sql
ALTER TABLE "EXAMPLE_SCHEDULER" ADD "DELAY" INTERVAL DAY(9) TO SECOND(6)
DEFAULT 0:05:00 NOT NULL;
}}}
this query has two issues:
1. the duration is not enclosed in quotes `0:05:00` -> `'0:05:00'`
2. oracle requires the day to be in the value `'0:05:00'` -> `'0 0:05:00'`
----
== SUGGESTED FIX
A possible fix would be to ensure we format timedelta into the right
format when generating migrations, this means extending
`DatabaseSchemaEditor.prepare_default` to do the formatting before quoting
the value, right now `prepare_default` simply proxies the business logic
to `quote_value` which simply casts the timedelta to string.
----
== ENVIRONMENT
python venv:
{{{
Django==3.1
cx_Oracle==8.3.0
}}}
oracle version:
`Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production`
--
Ticket URL: <https://code.djangoproject.com/ticket/33358>
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/048.8d4c192d487c5544744b816b0953d334%40djangoproject.com.