Skip to content

Commit

Permalink
Fix setting the correlation ID in the database (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito authored Jun 12, 2024
1 parent 6f33a43 commit 69ff644
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .pyproject_generation/pyproject_custom.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "hexkit"
version = "3.2.1"
version = "3.2.2"
description = "A Toolkit for Building Microservices using the Hexagonal Architecture"
requires-python = ">=3.9"
classifiers = [
Expand Down
49 changes: 25 additions & 24 deletions lock/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ attrs==23.2.0 \
# via
# jsonschema
# referencing
boto3==1.34.123 \
--hash=sha256:42b140fc850cf261ee4b1e8ef527fa071b1f1592a6d6a68d34b29f37cc46b4dd \
--hash=sha256:56bec52d485d5670ce96d53ae7b2cd4ae4e8a705fb2298a21093cdd77d642331
boto3==1.34.124 \
--hash=sha256:549d9735bbb7cf8e1a2f4b3b676be32946717c59f33c47234586835dc904d04e \
--hash=sha256:a91ee58fa54b170f17b2e144f038e155f92cf515f1c073ac2595e9ee45f125a8
# via hexkit (pyproject.toml)
botocore==1.34.123 \
--hash=sha256:8c34ada2a708c82e7174bff700611643db7ce2cb18f1130c35045c24310d299d \
--hash=sha256:a8577f6574600c4d159b5cd103ee05744a443d77f7778304e17307940b369c4f
botocore==1.34.124 \
--hash=sha256:3f0bf79c17d656acdfdb53581224f6a38867ff2829f7428c586198f67a90ea26 \
--hash=sha256:fede092c7f8f414f78f3e7991e47cb0cf2279d90c027606ad7cba79fa370b827
# via
# hexkit (pyproject.toml)
# boto3
Expand Down Expand Up @@ -940,24 +940,25 @@ urllib3==2.2.1 \
# docker
# requests
# testcontainers
uv==0.2.10 \
--hash=sha256:22e605204ed9d1d53f5da61095a0664a686889b6493d72702066d2d19ec2940f \
--hash=sha256:27837a81e0a2ee5f904dcf5e7749687ad91e12554f5f3c11008aee0a39946312 \
--hash=sha256:4cfc7543b87ea3b1e2aa4e6a46b6c90f9e91e2d18aa0aaebb886e1060a12a7e1 \
--hash=sha256:59306d7a66d4e81f7db848b387bcb80895b4ac2cc461c44c621409ce707ae137 \
--hash=sha256:846a3c2b7f2a57958feff2cd992be5dbef024d1db865df59d92c86b999da013e \
--hash=sha256:8cae774246fbe2d3d769a1433d967a60c1cd2939b1e55f4d7bb47ecca3980ea6 \
--hash=sha256:a4c9197599bbcec77d3b3ce74d65bc3e19d17faedabe6656d0599e6b4cf6d620 \
--hash=sha256:acc6784c5ac2877496cf301193ba3c2faeb78babe3e5b37e4cfc282d16321ecf \
--hash=sha256:cc5ce4699ff0ed59eedd94ab2ebce47aa242f28ef49a598812634398ba040fb1 \
--hash=sha256:d216fd0e9eb13e61d704ce71bdc0efcfed5157b9043eabf7572ba7dc44bd0328 \
--hash=sha256:dec31ca88f86a19c66c4e2fa848a42b9838c49eb69a79068f65fd600c5957883 \
--hash=sha256:e1626244425f9dd913fb8ea50c68899bf55cc8c9cc9437c82ee4e6c2616056fa \
--hash=sha256:e262b85cee496f56ba34f785c327ce849e66589906f73698f1af9db1deb11eb2 \
--hash=sha256:e9b079c23a5059085a6f4aec40d9324c9ce7a18e7857ebd7e0bbea7365c57940 \
--hash=sha256:eee5219844958dcf7c28d45ebd27b759f80cbcc2abcfaabd07bbe0e6b5b12ecd \
--hash=sha256:eefc2cd55eebcce680c9e52e7218768263f6d1df080bc1f10765ca63903140d2 \
--hash=sha256:fcca7e0acc36576d29baac1edac186fd77b45d6f0925f5e634e66d2839e9c384
uv==0.2.11 \
--hash=sha256:17f429eaf2141d18be22b1dc751d95326b76aebf4b51b589ed4d2fd589792098 \
--hash=sha256:1ff5742a8daf427bcca99089287871c1b90e8087d8e66182f409a8a39df6eb2d \
--hash=sha256:20061c5795811eba07a1470f04dcc543255196c7e872e91ffc4b638dacd8cd0e \
--hash=sha256:33e1129b673054d17d014535bf868bb22051e9437963200a3eea7ddf8aaac6e0 \
--hash=sha256:3bae25daae60f3d59dd82197b8d87cb081bde985c91d5ba2b3bbdecd3ba9b557 \
--hash=sha256:3c3dfee56d0ca79e65dfb33522509d987bffa267fe31b7a48874652ff979c1fa \
--hash=sha256:6e3ff93020c28c4d518c1c77bfe0bb46de5949adff389df27ec117eaa4c9b279 \
--hash=sha256:7a4e8beb576a9d4245d763f2ae2eca709cf0c1a2a706c583c28f467cc99ec7d2 \
--hash=sha256:81687b0272f472dcd84de16da25cea21e8b697fed8603ecb62c8cdac0a842d15 \
--hash=sha256:8545cd5c3fd27fcb3bed1df4bae95ea33fe07460700091070973b3f1225fd8e7 \
--hash=sha256:8c3b267f2db93170c537efe9521820fef1c542ecf890c863f01ccbbf2ccef22e \
--hash=sha256:8f00713a3ef6ce46687521ab512bf78b391cf7247ac8500f217a6168cbb9c099 \
--hash=sha256:96d3e2dd7f8a1774a0c0070732cb7d670b23043d4860de4658ff7f597ede93f0 \
--hash=sha256:9da79f8eaebf56d71ad56887510a1a6875d67ec209e1ccceeb9732b8b27e0f5d \
--hash=sha256:a2708392c38eee38f2e69384d1f37db0451d89db78d5d98ed89b00e5653a4812 \
--hash=sha256:e7f24e40e24ddb66cf2b8bc4dd0a36ee7f727bf63b8c8f26fc5038cf931f98a2 \
--hash=sha256:edeb6314c9e4061917918016fc84b0cabdcc24a1b4e7d04032dbfb86d41f834e \
--hash=sha256:f66c5b627348f04bd9773c66dc54a007d42df115a07ccb84678bdb4e3b85836d
# via -r lock/requirements-dev-template.in
virtualenv==20.26.2 \
--hash=sha256:82bf0f4eebbb78d36ddaee0283d43fe5736b53880b8a8cdcd37390a07ac3741c \
Expand Down
12 changes: 6 additions & 6 deletions lock/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ attrs==23.2.0 \
# -c lock/requirements-dev.txt
# jsonschema
# referencing
boto3==1.34.123 \
--hash=sha256:42b140fc850cf261ee4b1e8ef527fa071b1f1592a6d6a68d34b29f37cc46b4dd \
--hash=sha256:56bec52d485d5670ce96d53ae7b2cd4ae4e8a705fb2298a21093cdd77d642331
boto3==1.34.124 \
--hash=sha256:549d9735bbb7cf8e1a2f4b3b676be32946717c59f33c47234586835dc904d04e \
--hash=sha256:a91ee58fa54b170f17b2e144f038e155f92cf515f1c073ac2595e9ee45f125a8
# via
# -c lock/requirements-dev.txt
# hexkit (pyproject.toml)
botocore==1.34.123 \
--hash=sha256:8c34ada2a708c82e7174bff700611643db7ce2cb18f1130c35045c24310d299d \
--hash=sha256:a8577f6574600c4d159b5cd103ee05744a443d77f7778304e17307940b369c4f
botocore==1.34.124 \
--hash=sha256:3f0bf79c17d656acdfdb53581224f6a38867ff2829f7428c586198f67a90ea26 \
--hash=sha256:fede092c7f8f414f78f3e7991e47cb0cf2279d90c027606ad7cba79fa370b827
# via
# -c lock/requirements-dev.txt
# hexkit (pyproject.toml)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ classifiers = [
"Intended Audience :: Developers",
]
name = "hexkit"
version = "3.2.1"
version = "3.2.2"
description = "A Toolkit for Building Microservices using the Hexagonal Architecture"
dependencies = [
"pydantic >=2, <3",
Expand Down
2 changes: 1 addition & 1 deletion src/hexkit/providers/mongokafka/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ async def update(self, dto: Dto) -> None:
"""
correlation_id = get_correlation_id()
document = self._dao._dto_to_document(dto)
document["__metadata__.correlation_id"] = correlation_id
document.setdefault("__metadata__", {})["correlation_id"] = correlation_id
result = await self._collection.replace_one(
{"_id": document["_id"], "__metadata__.deleted": False}, document
)
Expand Down
29 changes: 29 additions & 0 deletions tests/integration/test_mongokafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,11 @@ async def test_mongokafka_dao_correlation_id_upsert(mongo_kafka: MongoKafkaFixtu
collection = get_mongo_collection(mongo_kafka, "example")
inserted = collection.find_one({"__metadata__.correlation_id": correlation_id})
assert inserted
assert inserted["__metadata__"] == {
"correlation_id": correlation_id,
"deleted": False,
"published": True,
}

# Remove the metadata field and restore the ID field name, check against original
inserted_as_dto = document_to_dto(inserted, id_field="id", dto_model=ExampleDto)
Expand All @@ -567,6 +572,11 @@ async def test_mongokafka_dao_correlation_id_upsert(mongo_kafka: MongoKafkaFixtu
{"__metadata__.correlation_id": temp_correlation_id}
)
assert updated
assert updated["__metadata__"] == {
"correlation_id": temp_correlation_id,
"deleted": False,
"published": True,
}

# Remove the metadata field and restore the ID field name
updated_as_dto = document_to_dto(
Expand Down Expand Up @@ -601,6 +611,18 @@ async def test_mongokafka_dao_correlation_id_delete(mongo_kafka: MongoKafkaFixtu
correlation_id = get_correlation_id()
inserted = collection.find_one({"__metadata__.correlation_id": correlation_id})
assert inserted
metadata = inserted.pop("__metadata__")
assert inserted == {
"_id": "test1",
"field_a": "test",
"field_b": 1,
"field_c": False,
}
assert metadata == {
"correlation_id": correlation_id,
"deleted": False,
"published": True,
}

# Create a new correlation ID to simulate a subsequent request
async with set_new_correlation_id() as temp_correlation_id:
Expand All @@ -611,6 +633,13 @@ async def test_mongokafka_dao_correlation_id_delete(mongo_kafka: MongoKafkaFixtu
{"__metadata__.correlation_id": temp_correlation_id}
)
assert deleted
metadata = deleted.pop("__metadata__")
assert deleted == {"_id": "test1"}
assert metadata == {
"correlation_id": temp_correlation_id,
"deleted": True,
"published": True,
}

search_for_inserted_again = collection.find_one(
{"__metadata__.correlation_id": correlation_id}
Expand Down

0 comments on commit 69ff644

Please sign in to comment.