#23987 closed Bug (fixed)
sqlite backend doesn't always use effective_default()
| Reported by: | Andriy Sokolovskiy | Owned by: | Andriy Sokolovskiy |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Problem found here:
https://github.com/django/django/pull/3700#issuecomment-66838368
Look at this line:
https://github.com/django/django/blob/df9f2e41fae68e2079db61e07569fdc89d1d6343/django/db/backends/sqlite3/schema.py#L73
if field.has_default():
mapping[field.column] = self.quote_value(
self.effective_default(field)
)
Main is that effective default will be used only when field already has default.
That is not correct, because effective_default decides what default would be used.
The second minor problem is that field.has_default() check is already in effective_default method, so we don't need to call it twice.
Change History (9)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
As I can see need to have something like this.
Not sure about ManyToManyField, but without check for ManyToManyField some tests fails.
Index: django/django/db/backends/sqlite3/schema.py
===================================================================
--- django/django/db/backends/sqlite3/schema.py (date 1417898599000)
+++ django/django/db/backends/sqlite3/schema.py (revision )
@@ -69,8 +69,8 @@
# Add in any created fields
for field in create_fields:
body[field.name] = field
- # If there's a default, insert it into the copy map
- if field.has_default():
+ # Choose default and insert it into the copy map
+ if not isinstance(field, ManyToManyField):
mapping[field.column] = self.quote_value(
self.effective_default(field)
)
comment:3 by , 11 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:4 by , 11 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
comment:9 by , 11 years ago
| Summary: | sqlite backend don't always use effective_default → sqlite backend doesn't always use effective_default() |
|---|
If it will be reviewed as bug, I'll create patch for it.