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

[BUG]fetch_links=True doesn't work with Views #1011

Open
efrechette-rga opened this issue Aug 29, 2024 · 2 comments
Open

[BUG]fetch_links=True doesn't work with Views #1011

efrechette-rga opened this issue Aug 29, 2024 · 2 comments
Labels
bug Something isn't working feature request

Comments

@efrechette-rga
Copy link

Using fetch_links=True with a View results in an error:

  ...
  File ".../beanie/odm/queries/find.py", line 1042, in __await__
    document = yield from self._find_one().__await__()  # type: ignore
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../beanie/odm/queries/find.py", line 998, in _find_one
    return await self.document_model.find_many(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../beanie/odm/queries/find.py", line 701, in first_or_none
    res = await self.limit(1).to_list()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../beanie/odm/queries/cursor.py", line 72, in to_list
    cursor = self.motor_cursor
             ^^^^^^^^^^^^^^^^^
  File ".../beanie/odm/queries/find.py", line 674, in motor_cursor
    ] = self.build_aggregation_pipeline()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../beanie/odm/queries/find.py", line 623, in build_aggregation_pipeline
    ] = construct_lookup_queries(
        ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../beanie/odm/utils/find.py", line 32, in construct_lookup_queries
    database_major_version=cls._database_major_version,
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pydantic/_internal/_model_construction.py", line 237, in __getattr__
    raise AttributeError(item)
AttributeError: _database_major_version

To Reproduce

class MyView(View):
    some_field: str
    some_link: Link[MyOtherModel]

    class Settings:
        source = MyModel
        pipeline = ...

MyView.find_one(MyView.some_field == "hi", fetch_links=True)

Expected behavior
View.find_one(..., fetch_links=True) works exactly like it does for Documents.

Copy link
Contributor

This issue is stale because it has been open 30 days with no activity.

@github-actions github-actions bot added the Stale label Sep 29, 2024
@marconadar
Copy link

+1 fetch_links=True does not fully populate the linked documents but Object { id: "668ea3dda0a3e171ae3fbd71", collection: "users" } in the linked field of the linking document.

@github-actions github-actions bot removed the Stale label Oct 5, 2024
@staticxterm staticxterm added bug Something isn't working feature request labels Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature request
Projects
None yet
Development

No branches or pull requests

3 participants