Skip to content

Commit

Permalink
Rename arguments to be clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-selo committed Jun 26, 2023
1 parent e017d33 commit 579c5d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,24 @@ def start_test_execution(
artefact = get_or_create(
db,
Artefact,
kwargs={
filter_kwargs={
"name": request.name,
"version": request.version,
"source": request.source,
},
extra_create_kwargs={"stage_id": stage.id},
creation_kwargs={"stage_id": stage.id},
)

environment = get_or_create(
db,
Environment,
kwargs={"name": request.environment, "architecture": request.arch},
filter_kwargs={"name": request.environment, "architecture": request.arch},
)

artefact_build = get_or_create(
db,
ArtefactBuild,
kwargs={
filter_kwargs={
"architecture": request.arch,
"revision": request.revision,
"artefact_id": artefact.id,
Expand All @@ -81,11 +81,11 @@ def start_test_execution(
test_execution = get_or_create(
db,
TestExecution,
kwargs={
filter_kwargs={
"environment_id": environment.id,
"artefact_build_id": artefact_build.id,
},
extra_create_kwargs={
creation_kwargs={
"status": TestExecutionStatus.IN_PROGRESS,
},
)
Expand Down
14 changes: 7 additions & 7 deletions backend/test_observer/data_access/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,22 @@ def get_artefacts_by_family_name(
def get_or_create(
db: Session,
model: type[DataModel],
kwargs: dict,
extra_create_kwargs: dict | None = None,
filter_kwargs: dict,
creation_kwargs: dict | None = None,
) -> DataModel:
"""
Creates an object if it doesn't exist, otherwise returns the existing one
:db: DB session
:model: model to create e.g. Stage, Family, Artefact
:kwargs: arguments to pass to the model when querying and creating
:extra_create_kwargs: extra arguments to pass to the model when creating only
:filter_kwargs: arguments to pass to the model when querying and creating
:creation_kwargs: extra arguments to pass to the model when creating only
"""
# Try to create first to avoid race conditions
extra_create_kwargs = extra_create_kwargs or {}
creation_kwargs = creation_kwargs or {}
stmt = (
insert(model)
.values([{**kwargs, **extra_create_kwargs}])
.values([{**filter_kwargs, **creation_kwargs}])
.on_conflict_do_nothing()
.returning(model)
)
Expand All @@ -127,6 +127,6 @@ def get_or_create(

if result is None:
# If the object already existed, we need to query it
result = db.query(model).filter_by(**kwargs).one()
result = db.query(model).filter_by(**filter_kwargs).one()

return result

0 comments on commit 579c5d9

Please sign in to comment.