Skip to content
Snippets Groups Projects
Commit 57408e71 authored by Christophe Lallement's avatar Christophe Lallement
Browse files

Merge branch 'fix_commit_session_response' into 'master'

Fix commit session response

See merge request !461
parents d346f7b6 cd318e21
No related branches found
No related tags found
1 merge request!461Fix commit session response
Pipeline #98372 failed
......@@ -118,7 +118,7 @@ class StorageRecordServiceBlobStorage:
# manual for now
return CreateUpdateRecordsResponse(recordCount=len(record_list),
recordIds=[record.id for record in record_list],
recordIdVersions=[record.version for record in record_list],
recordIdVersions=[f"{record.id}:{record.version}" for record in record_list],
skipped_record_ids=[])
async def get_record_version(self,
......
......@@ -378,9 +378,11 @@ async def complete_session(
i_session.session.meta = i_session.session.meta or {}
i_session.session.meta.update({"some_detail_about_merge": "like the shape, number of rows ..."})
return CommitSessionResponse(
response = CommitSessionResponse(
**i_session.session.dict(exclude_unset=True, by_alias=True),
version=new_record.record_id_versions[0]
version=DMSV3RouterUtils.get_version_from_record_id_version(
new_record.record_id_versions[0]
)
)
return response
......
......@@ -25,6 +25,8 @@ from app.routers.bulk.bulk_uri_dependencies import BulkIdAccess
from app.routers.record_utils import fetch_record
from app.utils import Context, get_ctx
OSDU_ENTITY_VERSION_REGEX = re.compile(r"^[\w\-\.]+:[^\:]+:[\w\-\.\:\%]+:(?P<version>[0-9]+)$")
OSDU_WELL_VERSION_REGEX = re.compile(r"^([\w\-\.]+:master-data\-\-Well:[\w\-\.\:\%]+):([0-9]*)$")
OSDU_WELL_REGEX = re.compile(r"^[\w\-\.]+:master-data\-\-Well:[\w\-\.\:\%]+$")
......@@ -54,6 +56,15 @@ entity_names = {
class DMSV3RouterUtils:
@staticmethod
def get_version_from_record_id_version(record_id_version: str) -> int:
match = OSDU_ENTITY_VERSION_REGEX.match(record_id_version)
if not match:
raise RuntimeError(f"{record_id_version} is not a valid, it must match {OSDU_ENTITY_VERSION_REGEX}")
return int(match["version"])
@staticmethod
def is_osdu_wellbore_id(entity_id: str) -> bool:
return OSDU_WELLBORE_REGEX.match(entity_id) is not None
......
......@@ -45,3 +45,45 @@ GET_WO_VERSION_PARAMS = [
def test_get_id_without_version(version_regexp, record_id, expected_id):
record_wo_version = DMSV3RouterUtils.get_id_without_version(version_regexp, record_id)
assert record_wo_version == expected_id
@pytest.mark.parametrize(
"record_id_version, expected",
[
(
"opendes:work-product-component--WellLog:713b4988cca14719867ae3b1004edf4e:1234",
1234
),
(
"opendes:work-product-component--WellboreTrajectory:713b4988cca14719867ae3b1004edf4e:465",
465
),
(
"data-partition:work-product-component--WellLog:713b4988cca14719867ae3b1004edf4e:1646997150219714",
1646997150219714
),
(
"osdu:log:a01d160506bd4f22a323eb2734cb370c:1991106102849593087389851558600877159",
1991106102849593087389851558600877159
),
]
)
def test_get_version_from_record_id_version(record_id_version, expected):
computed = DMSV3RouterUtils.get_version_from_record_id_version(record_id_version)
assert computed == expected
@pytest.mark.parametrize(
"record_id_version",
[
"opendes:work-product-component--WellLog:713b4988cca14719867ae3b1004edf4e:",
"opendes:work-product-component--WellLog:713b4988cca14719867ae3b1004edf4e",
"dummy",
":::1324"
]
)
def test_get_version_from_record_id_version_raise(record_id_version):
with pytest.raises(RuntimeError):
DMSV3RouterUtils.get_version_from_record_id_version(record_id_version)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment