doableware / djongo

Django and MongoDB database connector
https://www.djongomapper.com
GNU Affero General Public License v3.0
1.89k stars 355 forks source link

id attribute is set to None on Django 3.0.5 But it works on Django 2.1 #501

Open ahmad88me opened 3 years ago

ahmad88me commented 3 years ago

One line description of the issue

Error deleting in Django 3.0.5 but works on Django 2.1

Python script

```python def delete_all_users(): for u in OUser.objects.all(): u.delete() u.save() OUser.objects.all().delete() def create_user(): sec = ''.join([random.choice(string.ascii_letters + string.digits) for _ in range(9)]) user = OUser.objects.create_user(email=os.environ['test_user_email'], username=os.environ['test_user_email'], password=os.environ['test_user_token'], token=sec) ``` The `models.py` can be found here: https://github.com/OnToology/OnToology/blob/djo/OnToology/models.py #### Traceback ``` Traceback (most recent call last): File "/playground/OnToology/OnToology/tests/test_direct_magic.py", line 87, in setUp delete_all_repos_from_db() File "/playground/OnToology/OnToology/tests/api_util.py", line 16, in delete_all_repos_from_db r.delete() File "/playground/OnToology/.venv/lib/python3.8/site-packages/django/db/models/base.py", line 931, in delete assert self.pk is not None, ( AssertionError: Repo object can't be deleted because its id attribute is set to None. ```
ahmad88me commented 3 years ago

Also breaks when I upgrade from django 2.1 to django 2.2.

ahmad88me commented 3 years ago

I think this might be related to part of whats new in 2.2. Django no longer always starts a transaction when a single query is being performed, such as Model.save(), QuerySet.update(), and Model.delete(). This improves the performance of autocommit by reducing the number of database round trips.