QuerySet operations returns Sequence instead of List
See original GitHub issueIssue Description
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:
- Created 2 years ago
- Comments:12 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
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! 😃