Skip to content

Commit 9c36c69

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent afabcd7 commit 9c36c69

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

api/environments/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from copy import deepcopy
55
from typing import TYPE_CHECKING, Literal
66

7-
from flagsmith_schemas.api import V1EnvironmentDocumentResponse
87
from common.core.utils import using_database_replica
98
from django.conf import settings
109
from django.contrib.contenttypes.fields import GenericRelation
@@ -21,6 +20,7 @@
2120
LifecycleModel,
2221
hook,
2322
)
23+
from flagsmith_schemas.api import V1EnvironmentDocumentResponse
2424
from rest_framework.request import Request
2525
from softdelete.models import SoftDeleteObject # type: ignore[import-untyped]
2626

@@ -363,16 +363,16 @@ def write_environment_documents(
363363
cache_payload = {}
364364
for e in environments:
365365
fat_doc = map_environment_to_environment_document(e)
366-
366+
367367
# Safely check for Pydantic V2's model_dump, with a fallback
368368
if hasattr(fat_doc, "model_dump"):
369369
doc_dict = fat_doc.model_dump()
370-
elif hasattr(fat_doc, "dict"):
370+
elif hasattr(fat_doc, "dict"):
371371
# Just in case Flagsmith has a legacy custom class here
372372
doc_dict = fat_doc.dict()
373373
else:
374374
doc_dict = fat_doc
375-
375+
376376
# Manually extract ONLY the keys allowed by the V1 TypedDict
377377
clean_doc: V1EnvironmentDocumentResponse = {
378378
"api_key": doc_dict.get("api_key"),

api/tests/unit/environments/test_unit_environments_models.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.db.models import Count, Q
1111
from django.test import override_settings
1212
from django.utils import timezone
13+
from flagsmith_schemas.api import V1EnvironmentDocumentResponse
1314
from mypy_boto3_dynamodb.service_resource import Table
1415
from pytest_django import DjangoAssertNumQueries
1516
from pytest_django.asserts import assertQuerySetEqual as assert_queryset_equal
@@ -19,9 +20,8 @@
1920
from audit.related_object_type import RelatedObjectType
2021
from core.constants import STRING
2122
from core.request_origin import RequestOrigin
22-
from environments.identities.models import Identity
2323
from environments.enums import EnvironmentDocumentCacheMode
24-
from flagsmith_schemas.api import V1EnvironmentDocumentResponse
24+
from environments.identities.models import Identity
2525
from environments.metrics import CACHE_HIT, CACHE_MISS
2626
from environments.models import (
2727
Environment,
@@ -1269,7 +1269,7 @@ def test_environment_clone_from_non_versioned_environment_with_use_v2_feature_ve
12691269
# When
12701270
new_environment = environment.clone(name="new-environment")
12711271

1272-
# Then
1272+
# Then
12731273
assert new_environment.use_v2_feature_versioning
12741274

12751275
# we only expect a single environment feature version as we are essentially
@@ -1283,15 +1283,14 @@ def test_environment_clone_from_non_versioned_environment_with_use_v2_feature_ve
12831283
assert latest_feature_states.count() == 2
12841284
assert {fs.environment_feature_version for fs in latest_feature_states} == {efv}
12851285

1286+
12861287
@mock.patch("environments.models.environment_document_cache")
12871288
def test_write_environment_documents_strips_internal_fields_from_cache(
1288-
mock_document_cache: MagicMock,
1289-
environment: Environment,
1290-
settings: typing.Any
1289+
mock_document_cache: MagicMock, environment: Environment, settings: typing.Any
12911290
) -> None:
12921291
# 1. SETUP: Force the persistent caching mode
12931292
settings.CACHE_ENVIRONMENT_DOCUMENT_MODE = EnvironmentDocumentCacheMode.PERSISTENT
1294-
1293+
12951294
# 2. ACTION: Trigger the document builder
12961295
Environment.write_environment_documents(environment_id=environment.id)
12971296

@@ -1304,7 +1303,7 @@ def test_write_environment_documents_strips_internal_fields_from_cache(
13041303
assert "compress_dynamo_documents" not in cached_document
13051304
assert "use_v2_feature_versioning" not in cached_document
13061305

1307-
# 5. SCHEMA VALIDATION: Prove the dictionary perfectly matches the TypedDict
1306+
# 5. SCHEMA VALIDATION: Prove the dictionary perfectly matches the TypedDict
13081307
# required by the API. If this raises an error, the fix failed.
13091308
clean_doc: V1EnvironmentDocumentResponse = {
13101309
"api_key": cached_document["api_key"],

0 commit comments

Comments
 (0)