Skip to content

Commit

Permalink
Fix _base_connection_cfg mutation bug
Browse files Browse the repository at this point in the history
Signed-off-by: Mynhardt Burger <Mynhardt.Burger@ibm.com>
  • Loading branch information
mynhardtburger committed Jun 7, 2024
1 parent e358d15 commit b87c958
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions caikit_tgis_backend/tgis_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""This module implements a TGIS backend configuration"""

# Standard
from copy import deepcopy
from threading import Lock
from typing import Any, Dict, Optional

Expand Down Expand Up @@ -197,10 +198,10 @@ def register_model_connection(
# Craft new connection config
new_conn_cfg = {}
if conn_cfg is None:
new_conn_cfg = self._base_connection_cfg
new_conn_cfg = deepcopy(self._base_connection_cfg)
else:
if fill_with_defaults:
new_conn_cfg = self._base_connection_cfg
new_conn_cfg = deepcopy(self._base_connection_cfg)
new_conn_cfg.update(conn_cfg)

# Create model connection
Expand Down
5 changes: 5 additions & 0 deletions tests/test_tgis_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

# Standard
from copy import deepcopy
from dataclasses import asdict
from typing import Any, Dict, Optional
from unittest import mock
Expand Down Expand Up @@ -736,6 +737,7 @@ def test_tgis_backend_register_model_connection(
# Assert new model is not in backend
assert model_id not in tgis_be._remote_models_cfg
assert model_id not in tgis_be._model_connections
backup_base_cfg = deepcopy(tgis_be._base_connection_cfg)

# Register model
tgis_be.register_model_connection(model_id, conn_cfg, fill_with_defaults=fill)
Expand Down Expand Up @@ -765,6 +767,9 @@ def test_tgis_backend_register_model_connection(
if v is not None
} == expected_conn_cfg

# Confirm that the source _base_connection_cfg wasn't mutated
assert tgis_be._base_connection_cfg == backup_base_cfg


## Failure Tests ###############################################################

Expand Down

0 comments on commit b87c958

Please sign in to comment.