Skip to content

Commit d83ffd8

Browse files
committed
uuidstr url converter instead of shadowing django uuid
1 parent 932d22b commit d83ffd8

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

ninja/signature/utils.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,11 @@ def get_args_names(func: Callable[..., Any]) -> List[str]:
7272
return list(inspect.signature(func).parameters.keys())
7373

7474

75-
class NinjaUUIDConverter:
75+
class UUIDStrConverter(UUIDConverter):
7676
"""Return a path converted UUID as a str instead of the standard UUID"""
7777

78-
regex = UUIDConverter.regex
79-
8078
def to_python(self, value: str) -> str:
81-
return value
82-
83-
def to_url(self, value: Any) -> str:
84-
return str(value)
79+
return value # return string value instead of UUID
8580

8681

87-
register_converter(NinjaUUIDConverter, "uuid")
82+
register_converter(UUIDStrConverter, "uuidstr")

tests/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def get_path_param_django_uuid(request, item_id: UUID):
174174
return item_id
175175

176176

177-
@router.get("/path/param-django-uuid-str/{uuid:item_id}")
177+
@router.get("/path/param-django-uuid-str/{uuidstr:item_id}")
178178
def get_path_param_django_uuid_str(request, item_id):
179179
assert isinstance(item_id, str)
180180
return item_id

tests/test_misc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ninja import NinjaAPI
88
from ninja.constants import NOT_SET
99
from ninja.signature.details import is_pydantic_model
10-
from ninja.signature.utils import NinjaUUIDConverter
10+
from ninja.signature.utils import UUIDStrConverter
1111
from ninja.testing import TestClient
1212

1313

@@ -48,7 +48,7 @@ def operation(request, a: str, *args, **kwargs):
4848

4949

5050
def test_uuid_converter():
51-
conv = NinjaUUIDConverter()
51+
conv = UUIDStrConverter()
5252
assert isinstance(conv.to_url(uuid.uuid4()), str)
5353

5454

0 commit comments

Comments
 (0)