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

Fixed the the type hint for Document.get() #1910

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions elasticsearch_dsl/_async/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async def get(
using: Optional[AsyncUsingType] = None,
index: Optional[str] = None,
**kwargs: Any,
) -> Optional[Self]:
) -> Self:
"""
Retrieve a single document from elasticsearch using its ``id``.

Expand All @@ -144,12 +144,11 @@ async def get(
:arg using: connection alias to use, defaults to ``'default'``

Any additional keyword arguments will be passed to
``Elasticsearch.get`` unchanged.
``Elasticsearch.get`` unchanged. If the given ``id`` is not found,
a ``NotFoundError`` exception is raised.
"""
es = cls._get_connection(using)
doc = await es.get(index=cls._default_index(index), id=id, **kwargs)
if not doc.get("found", False):
return None
return cls.from_es(doc)

@classmethod
Expand Down
7 changes: 3 additions & 4 deletions elasticsearch_dsl/_sync/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def get(
using: Optional[UsingType] = None,
index: Optional[str] = None,
**kwargs: Any,
) -> Optional[Self]:
) -> Self:
"""
Retrieve a single document from elasticsearch using its ``id``.

Expand All @@ -138,12 +138,11 @@ def get(
:arg using: connection alias to use, defaults to ``'default'``

Any additional keyword arguments will be passed to
``Elasticsearch.get`` unchanged.
``Elasticsearch.get`` unchanged. If the given ``id`` is not found,
a ``NotFoundError`` exception is raised.
"""
es = cls._get_connection(using)
doc = es.get(index=cls._default_index(index), id=id, **kwargs)
if not doc.get("found", False):
return None
return cls.from_es(doc)

@classmethod
Expand Down
Loading