Memory leak
Describe the issue I have come across a memory leak when running a particular test. We were using version 1.6.0 of model_bakery, and only when I reverted to version 1.0.0 was the issue resolved. I have tested all other versions including 1.1.0 and the issue persists.
To Reproduce I am not exactly sure what is causing this and so I will try to best describe the scenario. Create a model with 2 m2m fields which reference the same model:
class ModelA(models.Model):
types = models.ManyToManyField(ModelB)
subtypes = models.ManyToManyField(ModelB)
We also have a form where these fields can be edited where the user is able to pick any item from ModelB to be the value for type and subtype.
We have a simple test case where all we do something similar to the following:
import pytest
from django.test import Client
@pytest.fixture()
def site_a():
return baker.make(ModelB)
def test_something(self):
site_a.types.add(ModelB.objects.get(id=1), ModelB.objects.get(id=2))
client = Client()
url = ('url/to/the/edit/view')
response = client.get(url)
The test crashes on response = client.get(url) due to a memory leak. It seems usual that this is related to model_bakery, however, downgrading to version 1.0.0 fixed the issue.
Expected behavior For tests to pass/fail and not to instead crash.
Versions
- Python: 3.9.5
- Django: 3.2.11
- Model Bakery: 1.6.0
- Pytest: 6.2.1