Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions common/persistence/dynamo_persistence_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ async def add(self, key, data):
async with self.__get_dynamo_resource() as dynamo:
table = await dynamo.Table(self.table_name)
await table.put_item(
Item=self.add_primary_key_field(_KEY, key, data),
ConditionExpression=Attr(_KEY).not_exists())
except ClientError as e:
if e.response['Error']['Code'] == 'ConditionalCheckFailedException':
raise DuplicatePrimaryKeyError
raise
Item=self.add_primary_key_field(_KEY, key, data))
except Exception as e:
raise RecordCreationError from e

Expand Down
12 changes: 6 additions & 6 deletions common/persistence/mongo_persistence_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ async def add(self, key: str, data: dict):
logger.info('Adding data for {key} in table {table}', fparams={'key': key, 'table': self.table_name})

try:
result = await asyncio.to_thread(
lambda: self.collection.insert_one(self.add_primary_key_field(_KEY, key, data))
await asyncio.to_thread(
lambda: self.collection.find_one_and_replace(
{_KEY: key},
self.add_primary_key_field(_KEY, key, data),
upsert=True
)
)
if not result.acknowledged:
raise RecordCreationError
except DuplicateKeyError as e:
raise DuplicatePrimaryKeyError from e
except Exception as e:
raise RecordCreationError from e

Expand Down
2 changes: 1 addition & 1 deletion component-test.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN apt-get update \
swig=4.1.0-0.2 \
pkg-config=1.8.1-1 \
libxml2-dev=2.9.14+dfsg-1.3~deb12u5 \
libxslt1-dev=1.1.35-1+deb12u3 \
libxslt1-dev=1.1.35-1+deb12u4 \
python3-dev=3.11.2-1+b1 \
libffi-dev=3.4.4-1 \
&& apt-get clean \
Expand Down
2 changes: 1 addition & 1 deletion docker/inbound/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apt-get update \
libssl-dev=3.0.19-1~deb12u2 \
libffi-dev=3.4.4-1 \
libxml2-dev=2.9.14+dfsg-1.3~deb12u5 \
libxslt1-dev=1.1.35-1+deb12u3 \
libxslt1-dev=1.1.35-1+deb12u4 \
pkg-config=1.8.1-1 \
python3-dev=3.11.2-1+b1 \
swig=4.1.0-0.2 \
Expand Down
2 changes: 1 addition & 1 deletion docker/outbound/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN apt-get update \
swig=4.1.0-0.2 \
pkg-config=1.8.1-1 \
libxml2-dev=2.9.14+dfsg-1.3~deb12u5 \
libxslt1-dev=1.1.35-1+deb12u3 \
libxslt1-dev=1.1.35-1+deb12u4 \
python3-dev=3.11.2-1+b1 \
libffi-dev=3.4.4-1 \
&& apt-get clean \
Expand Down
2 changes: 1 addition & 1 deletion docker/spineroutelookup/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN apt-get update \
build-essential=12.9 \
libssl-dev=3.0.19-1~deb12u2 \
libxml2-dev=2.9.14+dfsg-1.3~deb12u5 \
libxslt1-dev=1.1.35-1+deb12u3 \
libxslt1-dev=1.1.35-1+deb12u4 \
libffi-dev=3.4.4-1 \
pkg-config=1.8.1-1 \
python3-dev=3.11.2-1+b1 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def test_can_CRUD(self):
value = await adaptor.get(other_key)
self.assertIsNone(value)

async def test_error_if_same_key_inserted_twice(self):
async def test_can_reinsert_same_key(self):
for adaptor_type in PERSISTENCE_ADAPTOR_TYPES:
with self.subTest(f"{adaptor_type}"):
adaptor = self.get_adaptor(adaptor_type)
Expand All @@ -98,14 +98,10 @@ async def test_error_if_same_key_inserted_twice(self):
self.keys += [key]

await adaptor.add(key, OTHER_DATA)
await adaptor.add(key, SAMPLE_DATA)

try:
await adaptor.add(key, OTHER_DATA)
except MaxRetriesExceeded as e:
cause = e.__cause__
self.assertIsInstance(cause, DuplicatePrimaryKeyError)
else:
self.fail(f"Expected '{type(DuplicatePrimaryKeyError)}' exception not raised")
value = await adaptor.get(key)
self.assertEqual(value, SAMPLE_DATA)

async def test_error_if_data_to_add_has_primary_key_in(self):
await self._test_error_if_data_has_primary_key_in(PersistenceAdaptor.add.__name__)
Expand Down
Loading