Skip to content

Commit ad4d2cf

Browse files
committed
fix: remove mutable defaults #187
1 parent e4f7427 commit ad4d2cf

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

commons/data_access_layer/cosmos_db.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ def __init__(
9292
container_id: str,
9393
partition_key_attribute: str,
9494
mapper: Callable = None,
95-
order_fields: list = [],
95+
order_fields: list = None,
9696
custom_cosmos_helper: CosmosDBFacade = None,
9797
):
9898
global cosmos_helper
9999
self.cosmos_helper = custom_cosmos_helper or cosmos_helper
100100
if self.cosmos_helper is None: # pragma: no cover
101101
raise ValueError("The cosmos_db module has not been initialized!")
102102
self.mapper = mapper
103-
self.order_fields = order_fields
103+
self.order_fields = order_fields if order_fields else []
104104
self.container: ContainerProxy = self.cosmos_helper.db.get_container_client(
105105
container_id
106106
)
@@ -224,14 +224,20 @@ def find(
224224
def find_all(
225225
self,
226226
event_context: EventContext,
227-
conditions: dict = {},
228-
custom_sql_conditions: List[str] = [],
229-
custom_params: dict = {},
227+
conditions: dict = None,
228+
custom_sql_conditions: List[str] = None,
229+
custom_params: dict = None,
230230
max_count=None,
231231
offset=0,
232232
visible_only=True,
233233
mapper: Callable = None,
234234
):
235+
conditions = conditions if conditions else {}
236+
custom_sql_conditions = (
237+
custom_sql_conditions if custom_sql_conditions else []
238+
)
239+
custom_params = custom_params if custom_params else {}
240+
235241
partition_key_value = self.find_partition_key_value(event_context)
236242
max_count = self.get_page_size_or(max_count)
237243
params = [

time_tracker_api/time_entries/time_entries_model.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,15 @@ def create_sql_date_range_filter(date_range: dict) -> str:
160160
def find_all_entries(
161161
self,
162162
event_context: EventContext,
163-
conditions: dict = {},
163+
conditions: dict = None,
164164
custom_sql_conditions: List[str] = None,
165-
date_range: dict = {},
165+
date_range: dict = None,
166166
):
167-
if custom_sql_conditions is None:
168-
custom_sql_conditions = []
167+
conditions = conditions if conditions else {}
168+
custom_sql_conditions = (
169+
custom_sql_conditions if custom_sql_conditions else []
170+
)
171+
date_range = date_range if date_range else {}
169172

170173
custom_sql_conditions.append(
171174
self.create_sql_date_range_filter(date_range)
@@ -184,11 +187,17 @@ def find_all_entries(
184187
def find_all(
185188
self,
186189
event_context: EventContext,
187-
conditions: dict = {},
188-
custom_sql_conditions: List[str] = [],
189-
date_range: dict = {},
190+
conditions: dict = None,
191+
custom_sql_conditions: List[str] = None,
192+
date_range: dict = None,
190193
**kwargs,
191194
):
195+
conditions = conditions if conditions else {}
196+
custom_sql_conditions = (
197+
custom_sql_conditions if custom_sql_conditions else []
198+
)
199+
date_range = date_range if date_range else {}
200+
192201
custom_sql_conditions.append(
193202
self.create_sql_date_range_filter(date_range)
194203
)
@@ -486,7 +495,7 @@ def find_running(self):
486495
# self.stop_time_entry_if_was_left_running(time_entry)
487496
return time_entry
488497

489-
def get_worked_time(self, args: dict = {}):
498+
def get_worked_time(self, args: dict):
490499
event_ctx = self.create_event_context(
491500
"read", "Summary of worked time in the current month"
492501
)

0 commit comments

Comments
 (0)