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

Fix re-use of indexes and refresh method on null attributes #807

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 9 additions & 12 deletions pynamodb/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ def __init__(self) -> None:
if not hasattr(self.Meta, "projection"):
raise ValueError("No projection defined, define a projection for this class")

@classmethod
def count(
cls,
self,
hash_key: _KeyType,
range_key_condition: Optional[Condition] = None,
filter_condition: Optional[Condition] = None,
Expand All @@ -68,19 +67,18 @@ def count(
"""
Count on an index
"""
return cls.Meta.model.count(
return self._model.count(
hash_key,
range_key_condition=range_key_condition,
filter_condition=filter_condition,
index_name=cls.Meta.index_name,
index_name=self.Meta.index_name,
consistent_read=consistent_read,
limit=limit,
rate_limit=rate_limit,
)

@classmethod
def query(
cls,
self,
hash_key: _KeyType,
range_key_condition: Optional[Condition] = None,
filter_condition: Optional[Condition] = None,
Expand All @@ -95,12 +93,12 @@ def query(
"""
Queries an index
"""
return cls.Meta.model.query(
return self._model.query(
hash_key,
range_key_condition=range_key_condition,
filter_condition=filter_condition,
consistent_read=consistent_read,
index_name=cls.Meta.index_name,
index_name=self.Meta.index_name,
scan_index_forward=scan_index_forward,
limit=limit,
last_evaluated_key=last_evaluated_key,
Expand All @@ -109,9 +107,8 @@ def query(
rate_limit=rate_limit,
)

@classmethod
def scan(
cls,
self,
filter_condition: Optional[Condition] = None,
segment: Optional[int] = None,
total_segments: Optional[int] = None,
Expand All @@ -125,15 +122,15 @@ def scan(
"""
Scans an index
"""
return cls.Meta.model.scan(
return self._model.scan(
filter_condition=filter_condition,
segment=segment,
total_segments=total_segments,
limit=limit,
last_evaluated_key=last_evaluated_key,
page_size=page_size,
consistent_read=consistent_read,
index_name=cls.Meta.index_name,
index_name=self.Meta.index_name,
rate_limit=rate_limit,
attributes_to_get=attributes_to_get,
)
Expand Down
4 changes: 2 additions & 2 deletions pynamodb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def __init__(self, name: str, bases: Any, attrs: Dict[str, Any]) -> None:
if not hasattr(attr_obj, 'aws_session_token'):
setattr(attr_obj, 'aws_session_token', None)
elif isinstance(attr_obj, Index):
attr_obj.Meta.model = cls
attr_obj._model = cls
if not hasattr(attr_obj.Meta, "index_name"):
attr_obj.Meta.index_name = attr_name
elif isinstance(attr_obj, Attribute):
Expand Down Expand Up @@ -452,7 +452,7 @@ def refresh(self, consistent_read: bool = False) -> None:
:param consistent_read: If True, then a consistent read is performed.
:raises ModelInstance.DoesNotExist: if the object to be updated does not exist
"""
args, kwargs = self._get_save_args(attributes=False)
args, kwargs = self._get_save_args(attributes=False, null_check=False)
kwargs.setdefault('consistent_read', consistent_read)
attrs = self._get_connection().get_item(*args, **kwargs)
item_data = attrs.get(ITEM, None)
Expand Down