question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

QuerySet operations returns Sequence instead of List

See original GitHub issue

Describe the bug The QuerySet operations return value is Sequence[“Model”] even though on the DocString it is stated as List[“Model”] It is causing for lint errors as mismatch types when trying to retrieve the returned object as List.

for example:

rows: List[User] = await User.objects.all()

Will cause a lint error on mismatch type.

Looking into Ormar source code it seems the first time where this is starting to get confused is at: ormar.models.mixins.merge_mixin.py ==> merge_instances_list class method

from source-code:

@classmethod
    def merge_instances_list(cls, result_rows: Sequence["Model"]) -> Sequence["Model"]:
        """
        Merges a list of models into list of unique models.

        Models can duplicate during joins when parent model has multiple child rows,
        in the end all parent (main) models should be unique.

        :param result_rows: list of already initialized Models with child models
        populated, each instance is one row in db and some models can duplicate
        :type result_rows: List["Model"]
        :return: list of merged models where each main model is unique
        :rtype: List["Model"]
        """

as you can see rtype on DocString is List[“Model”] while the annotated return type is Sequence[“Model”].

If there is any specific reason and I can assist with fixing - I will be very happy to do so! The package is very helpful and it is much appreciated!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
collerekcommented, Mar 5, 2021

Ok, since this one should be fixed and we still have #112 I will close this one, we can discuss either in 112 or #124

0reactions
collerekcommented, Mar 5, 2021

Yeah, I merged the m2m branch to release it and now we can peacefully work on this one and rest of the issues 😃 Thanks for your work, will check the PR and proposed fix! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to return queryset instead of list? - python - Stack Overflow
This returns the correct list of data but I want queryset instead of list. How can I return the queryset instead of making...
Read more >
QuerySet API reference | Django documentation
Django provides a range of QuerySet refinement methods that modify either the types of results returned by the QuerySet or the way its...
Read more >
Storing Database ORM Operations as Data - HedgeDoc - Monadical
This post outlines a technique that can be used to queue database ORM operations in a data structure instead of in imperative code...
Read more >
How to check if an element is present in a Django queryset
Is it like a regular python set? Suppose I have the following queryset entry_set = Entry. ... check if Entry Object e is...
Read more >
Getting Started — django-filter 22.1 documentation
... a queryset based on parameters a user provides. Say we have a Product model and we want to let our users filter...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found