Skip to content

Commit 38e4a09

Browse files
authored
fix(experimentation): always insert new WarehouseConnection on create (#7605)
1 parent 2a13539 commit 38e4a09

3 files changed

Lines changed: 8 additions & 26 deletions

File tree

api/experimentation/serializers.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from environments.models import Environment
66
from experimentation.models import (
77
WarehouseConnection,
8-
WarehouseConnectionStatus,
98
WarehouseType,
109
)
1110
from experimentation.types import SNOWFLAKE_DEFAULTS, SnowflakeConfig
@@ -51,23 +50,6 @@ def create(
5150
if not validated_data.get("name"):
5251
validated_data["name"] = self._generate_name(warehouse_type, environment)
5352

54-
existing: WarehouseConnection | None = (
55-
WarehouseConnection.objects.all_with_deleted()
56-
.filter(
57-
environment=environment,
58-
warehouse_type=warehouse_type,
59-
deleted_at__isnull=False,
60-
)
61-
.first()
62-
)
63-
if existing:
64-
existing.deleted_at = None
65-
existing.status = WarehouseConnectionStatus.CREATED
66-
existing.name = validated_data["name"]
67-
existing.config = validated_data.get("config")
68-
existing.save()
69-
return existing
70-
7153
result: WarehouseConnection = super().create(validated_data)
7254
return result
7355

api/tests/unit/experimentation/test_serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_create__no_existing__creates_new_connection(
3030
assert connection.name == f"Flagsmith Warehouse - {environment.name}"
3131

3232

33-
def test_create__soft_deleted_exists__resurrects_record(
33+
def test_create__soft_deleted_exists__creates_new_record(
3434
environment: Environment,
3535
) -> None:
3636
# Given
@@ -51,7 +51,7 @@ def test_create__soft_deleted_exists__resurrects_record(
5151
connection = serializer.save(environment=environment)
5252

5353
# Then
54-
assert connection.pk == original_pk
54+
assert connection.pk != original_pk
5555
assert connection.deleted_at is None
5656
assert connection.status == WarehouseConnectionStatus.CREATED
5757
assert connection.name == f"Flagsmith Warehouse - {environment.name}"

api/tests/unit/experimentation/test_views.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_post__different_type_already_exists__returns_409(
9393
)
9494

9595

96-
def test_post__soft_deleted_exists__resurrects_and_returns_201(
96+
def test_post__soft_deleted_exists__creates_new_record_and_returns_201(
9797
admin_client: APIClient,
9898
environment: Environment,
9999
enable_features: EnableFeaturesFixture,
@@ -114,7 +114,7 @@ def test_post__soft_deleted_exists__resurrects_and_returns_201(
114114

115115
# Then
116116
assert response.status_code == status.HTTP_201_CREATED
117-
assert response.json()["id"] == original_id
117+
assert response.json()["id"] != original_id
118118
assert response.json()["status"] == "created"
119119

120120

@@ -487,7 +487,7 @@ def test_post__snowflake_no_name__auto_generates_name(
487487
assert response.json()["name"] == f"Snowflake Warehouse - {environment.name}"
488488

489489

490-
def test_post__snowflake_soft_deleted__resurrects_with_new_config(
490+
def test_post__snowflake_soft_deleted__creates_new_record_with_new_config(
491491
admin_client: APIClient,
492492
environment: Environment,
493493
enable_features: EnableFeaturesFixture,
@@ -516,7 +516,7 @@ def test_post__snowflake_soft_deleted__resurrects_with_new_config(
516516
warehouse_connection_url,
517517
data={
518518
"warehouse_type": "snowflake",
519-
"name": "Resurrected",
519+
"name": "Replacement",
520520
"config": {"account_identifier": "new.us-west-2"},
521521
},
522522
format="json",
@@ -525,9 +525,9 @@ def test_post__snowflake_soft_deleted__resurrects_with_new_config(
525525
# Then
526526
assert response.status_code == status.HTTP_201_CREATED
527527
data = response.json()
528-
assert data["id"] == original_id
528+
assert data["id"] != original_id
529529
assert data["status"] == "created"
530-
assert data["name"] == "Resurrected"
530+
assert data["name"] == "Replacement"
531531
assert data["config"]["account_identifier"] == "new.us-west-2"
532532

533533

0 commit comments

Comments
 (0)