Skip to content

Commit a4c258f

Browse files
committed
refactor: improve extension attribute urn making
use isinstance(x, Extension) instead of guessing by searching for a : symbol in the urn
1 parent 7388027 commit a4c258f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

scim2_models/base.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from inspect import isclass
2-
from typing import TYPE_CHECKING
32
from typing import Any
43
from typing import Optional
54
from typing import get_args
@@ -29,9 +28,6 @@
2928

3029
from .utils import UNION_TYPES
3130

32-
if TYPE_CHECKING:
33-
pass
34-
3531

3632
def contains_attribute_or_subattributes(
3733
attribute_urns: list[str], attribute_urn: str
@@ -448,13 +444,17 @@ def get_attribute_urn(self, field_name: str) -> str:
448444
449445
See :rfc:`RFC7644 §3.10 <7644#section-3.10>`.
450446
"""
447+
from scim2_models.rfc7643.resource import Extension
448+
451449
main_schema = self.__class__.model_fields["schemas"].default[0]
452-
alias = (
453-
self.__class__.model_fields[field_name].serialization_alias or field_name
450+
field = self.__class__.model_fields[field_name]
451+
alias = field.serialization_alias or field_name
452+
field_type = self.get_field_root_type(field_name)
453+
full_urn = (
454+
alias
455+
if isclass(field_type) and issubclass(field_type, Extension)
456+
else f"{main_schema}:{alias}"
454457
)
455-
456-
# if alias contains a ':' this is an extension urn
457-
full_urn = alias if ":" in alias else f"{main_schema}:{alias}"
458458
return full_urn
459459

460460

0 commit comments

Comments
 (0)