Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #329

Closed
Salaah01 opened this issue Jun 27, 2022 · 3 comments
Closed

Memory leak #329

Salaah01 opened this issue Jun 27, 2022 · 3 comments

Comments

@Salaah01
Copy link

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
@timjklein36
Copy link
Collaborator

@Salaah01 Thanks for submitting this issue!

A little more info would be very helpful to see if this particular scenario can be reproduced.

We also have a form where these fields can be edited

Is there any chance you can share the view code? (or a simplified copy of the code that calls model_bakery and produces the leak?) Assuming, that is, that 'url/to/the/edit/view', from your sample test, refers to that form being used on said view.

Also, to clarify, does the process simply stall indefinitely? Or are you getting some sort of exception / stack trace?

Thanks in advance.

timjklein36 added a commit to timjklein36/model_bakery that referenced this issue Oct 14, 2022
timjklein36 added a commit to timjklein36/model_bakery that referenced this issue Oct 14, 2022
@berinhard
Copy link
Member

@Salaah01 just by upgrading bakery to a new version, doesn't enforces it as being the root of your memory leak. Actually, your test crashes at your self.client.get request, it means that it's definitely not model-bakery causing it. This is because model-bakery doesn't do anything else outside the baker.make and baker.prepare method.

Anyway, as suggested by @timjklein36, can you share the traceback with us? Another suggestion is to run this test with the memory leak with a python profiler tool so you can check where the memory is leaking indeed.

@amureki
Copy link
Collaborator

amureki commented Oct 27, 2023

I am going to close the issue, as there is no new input.
Please, feel free to comment/reopen the issue, if this still a problem.

@amureki amureki closed this as completed Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants