#30382: force_insert flag is not passed when saving parents on inherited models.
-------------------------------------+-------------------------------------
Reporter: Phill Tornroth | Owner: Akash
| Kumar Sen
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
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 Natalia Bidart):
Hello phill-tornroth,
I'm trying to reproduce the reported issue in order to properly review the
proposed PR. I'm not able to generate the three queries you mentioned
(`UPDATE`, `INSERT`, `INSERT`). What I see using sqlite, PG or MySQL is
the same thing:
{{{
1. SELECT 1 AS `a` FROM `ticket_30382_parentmodel` WHERE
`ticket_30382_parentmodel`.`id` = 1 LIMIT 1
2. INSERT INTO `ticket_30382_parentmodel` (`id`) VALUES (1)
3. INSERT INTO `ticket_30382_childmodel` (`parentmodel_ptr_id`) VALUES (1)
}}}
Could you share your setup to provide instructions in how to reproduce the
reported problem?
My `models.py`:
{{{
from django.db import models
class ParentModel(models.Model):
id = models.BigIntegerField(primary_key=True)
class ChildModel(ParentModel):
pass
}}}
My `tests.py`:
{{{
from django.test import TestCase
from .models import ChildModel
class Ticke30382TestCase(TestCase):
def test_force_insert_save(self):
with self.assertNumQueries(0):
ChildModel(id=1).save(force_insert=True)
}}}
My test run:
{{{
======================================================================
FAIL: test_force_insert_save
(ticket_30382.tests.Ticke30382TestCase.test_force_insert_save)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/nessita/fellowship/projectfromrepo/ticket_30382/tests.py",
line 9, in test_force_insert_save
with self.assertNumQueries(0):
File "/home/nessita/.virtualenvs/djangodev/lib/python3.11/site-
packages/django/test/testcases.py", line 99, in __exit__
self.test_case.assertEqual(
AssertionError: 3 != 0 : 3 queries executed, 0 expected
Captured queries were:
1. SELECT 1 AS `a` FROM `ticket_30382_parentmodel` WHERE
`ticket_30382_parentmodel`.`id` = 1 LIMIT 1
2. INSERT INTO `ticket_30382_parentmodel` (`id`) VALUES (1)
3. INSERT INTO `ticket_30382_childmodel` (`parentmodel_ptr_id`) VALUES (1)
----------------------------------------------------------------------
Ran 1 test in 0.038s
}}}
Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/30382#comment:9>
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/01070187fc620b58-5598328a-ec04-4e15-8bc5-825bc0e71f44-000000%40eu-central-1.amazonses.com.