Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Merge requests
!295
Fix modify_site workflow where a site was modified to contain the same information as before
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Fix modify_site workflow where a site was modified to contain the same information as before
feature/update-modify-site
into
develop
Overview
0
Commits
1
Pipelines
2
Changes
4
Merged
Karel van Klink
requested to merge
feature/update-modify-site
into
develop
6 months ago
Overview
0
Commits
1
Pipelines
2
Changes
4
Expand
0
0
Merge request reports
Compare
develop
version 1
bec80d60
6 months ago
develop (base)
and
latest version
latest version
c1eadccb
1 commit,
6 months ago
version 1
bec80d60
1 commit,
6 months ago
4 files
+
94
−
51
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
gso/utils/types/unique_field.py
+
9
−
3
Options
"""
An input field that must be unique in the database.
"""
from
functools
import
partial
from
typing
import
Annotated
,
TypeVar
from
pydantic
import
AfterValidator
from
pydantic_core.core_schema
import
ValidationInfo
from
pydantic_forms.types
import
UUIDstr
from
gso.services
import
subscriptions
T
=
TypeVar
(
"
T
"
)
def
validate_field_is_unique
(
value
:
T
,
info
:
ValidationInfo
)
->
T
:
def
validate_field_is_unique
(
subscription_id
:
UUIDstr
,
value
:
T
,
info
:
ValidationInfo
)
->
T
:
"""
Validate that a field is unique.
"""
if
len
(
subscriptions
.
get_active_subscriptions_by_field_and_value
(
str
(
info
.
field_name
),
str
(
value
)))
>
0
:
matched_subscriptions
=
subscriptions
.
get_active_subscriptions_by_field_and_value
(
str
(
info
.
field_name
),
str
(
value
))
matched_subscriptions
=
list
(
filter
(
lambda
match
:
str
(
match
.
subscription_id
)
!=
subscription_id
,
matched_subscriptions
)
)
if
len
(
matched_subscriptions
)
>
0
:
msg
=
f
"
{
info
.
field_name
}
must be unique
"
raise
ValueError
(
msg
)
return
value
UniqueField
=
Annotated
[
T
,
AfterValidator
(
validate_field_is_unique
)]
UniqueField
=
Annotated
[
T
,
AfterValidator
(
partial
(
validate_field_is_unique
,
""
)
)]
Loading