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: don't share default values in ArchiveField #67

Merged
merged 1 commit into from
Aug 16, 2023
Merged
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
4 changes: 2 additions & 2 deletions database/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def should_write_to_storage(self) -> bool:
_report_json_storage_path = Column("report_storage_path", types.Text, nullable=True)
report_json = ArchiveField(
should_write_to_storage_fn=should_write_to_storage,
default_value={},
default_value_class=dict,
)


Expand Down Expand Up @@ -358,7 +358,7 @@ def should_write_to_storage(self) -> bool:
_flare = Column("flare", postgresql.JSON)
_flare_storage_path = Column("flare_storage_path", types.Text, nullable=True)
flare = ArchiveField(
should_write_to_storage_fn=should_write_to_storage, default_value={}
should_write_to_storage_fn=should_write_to_storage, default_value_class=dict
)


Expand Down
2 changes: 1 addition & 1 deletion database/models/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _should_write_to_storage(self) -> bool:
files_array = ArchiveField(
should_write_to_storage_fn=_should_write_to_storage,
rehydrate_fn=rehydrate_encoded_data,
default_value=[],
default_value_class=list,
)


Expand Down
4 changes: 1 addition & 3 deletions database/tests/unit/test_model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def __init__(
self._archive_field_storage_path = archive_value
self.should_write_to_gcs = should_write_to_gcs

archive_field = ArchiveField(
should_write_to_storage_fn=should_write_to_storage, default_value=None
)
archive_field = ArchiveField(should_write_to_storage_fn=should_write_to_storage)

class ClassWithArchiveFieldMissingMethods:
commit: Commit
Expand Down
8 changes: 4 additions & 4 deletions database/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def __init__(
should_write_to_storage_fn: Callable[[object], bool],
rehydrate_fn: Callable[[object, object], Any] = lambda self, x: x,
json_encoder=ReportEncoder,
default_value=None,
default_value_class=lambda: None,
):
self.default_value = default_value
self.default_value_class = default_value_class
self.rehydrate_fn = rehydrate_fn
self.should_write_to_storage_fn = should_write_to_storage_fn
self.json_encoder = json_encoder
Expand Down Expand Up @@ -103,14 +103,14 @@ def _get_value_from_archive(self, obj):
),
)
else:
log.info(
log.debug(
"Both db_field and archive_field are None",
extra=dict(
object_id=obj.id,
commit=obj.get_commitid(),
),
)
return self.default_value
return self.default_value_class()

def __get__(self, obj, objtype=None):
cached_value = getattr(obj, self.cached_value_property_name, None)
Expand Down
Loading