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

MultiModelField fails when validating large Querysets #76

Open
peterfarrell opened this issue Dec 19, 2022 · 0 comments
Open

MultiModelField fails when validating large Querysets #76

peterfarrell opened this issue Dec 19, 2022 · 0 comments

Comments

@peterfarrell
Copy link
Contributor

When using large Querysets as the input to MultipleModelField, the service fails (usually to out of memory / timeouts). This occurs because the Queryset is evaluated in clean as the MultipleModelField tries to evaluate that all items in the iteration are of type app.Thing.

This breaks even if you are handling large querysets with chunking in the process method.

class DoSomethingToThings(Service):
    things = MultipleModelField("app.Thing", required=True)

    def process(self):
        for thing in Model.objects.all().iterator(chunk_size=2000):
            pass  # Do something

Not sure how to handle this in MultipleModelField as iterable datatypes like list and tuples in addition to Django Querysets. Also, it has an unsaved check for model objects.

Propose a QuerysetField that accept Django Querysets of a certain type only. I will make a PR.

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

1 participant