[Django] #33064: Created Model is not showing in Django Atomic Trasaction Block

7 views
Skip to first unread message

Django

unread,
Aug 27, 2021, 2:07:14 AM8/27/21
to django-...@googlegroups.com
#33064: Created Model is not showing in Django Atomic Trasaction Block
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
dipensompura |
Type: Bug | Status: new
Component: | Version: 3.1
Uncategorized | Keywords: transaction atomic
Severity: Normal | mysql
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Following code not working, it should increase count within the block
itself:

I am using django with mysql database.
{{{#!python
>>> len(ModelObject.objects.all())
89
>>> with transaction.atomic():
... ModelObject.objects.create(modelId="123")
... print(len(ModelObject.objects.all()))
...
<ModelObject: ModelObject object (16125)>
89
>>> len(ModelObject.objects.all())
90
}}}

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

Django

unread,
Aug 27, 2021, 5:13:34 AM8/27/21
to django-...@googlegroups.com
#33064: Created Model is not showing in Django Atomic Trasaction Block
-------------------------------------+-------------------------------------
Reporter: Dipen Sompura | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: transaction atomic | Triage Stage:
mysql | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => worksforme
* component: Uncategorized => Database layer (models, ORM)


Comment:

Thanks for the report, however I cannot reproduce this issue on MySQL
(8.0.26, 5.6.50), SQLite, or PostgreSQL.

Please reopen the ticket if you can debug your issue and provide details
about why and where Django is at fault.

--
Ticket URL: <https://code.djangoproject.com/ticket/33064#comment:1>

Django

unread,
Aug 27, 2021, 7:35:12 AM8/27/21
to django-...@googlegroups.com
#33064: Created Model is not showing in Django Atomic Trasaction Block
-------------------------------------+-------------------------------------
Reporter: Dipen Sompura | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: transaction atomic | Triage Stage:
mysql | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Dipen Sompura):

Replying to [comment:1 Mariusz Felisiak]:


> Thanks for the report, however I cannot reproduce this issue on MySQL
(8.0.26, 5.6.50), SQLite, or PostgreSQL.
>
> Please reopen the ticket if you can debug your issue and provide details
about why and where Django is at fault.

Thank you for looking into this. I am able to debug the issue. We are
using reader and writer db instance with following DB router:

{{{#!python
class DBRouter:

def db_for_read(self, model, **hints):
"""Return read replica."""
return 'replica1'

def db_for_write(self, model, **hints):
# Always return the default database
return 'default'

def allow_relation(self, obj1, obj2, **hints):
return True

def allow_migrate(self, db, app_label, model_name=None, **hints):
return True
}}}

Any suggestion, where we can use same writer instance for the atomic block
by keeping my DBRouter configuration as is?

--
Ticket URL: <https://code.djangoproject.com/ticket/33064#comment:2>

Reply all
Reply to author
Forward
0 new messages