Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Object of type Url is not JSON serializable #1334

Open
jleclanche opened this issue Nov 9, 2024 · 0 comments · May be fixed by #1349
Open

[BUG] Object of type Url is not JSON serializable #1334

jleclanche opened this issue Nov 9, 2024 · 0 comments · May be fixed by #1349

Comments

@jleclanche
Copy link

Describe the bug
django-ninja = "^1.3.0"

Using HttpUrl (or, I suspect, any *Url class) for a schema used in a response results in json serialization error. This is the same type of issue as #717.

Traceback (most recent call last):
  File "/home/adys/.cache/pypoetry/virtualenvs/fabrile-backend-fklT6p4J-py3.10/lib/python3.10/site-packages/ninja/operation.py", line 121, in run
    return self._result_to_response(request, result, temporal_response)
  File "/home/adys/.cache/pypoetry/virtualenvs/fabrile-backend-fklT6p4J-py3.10/lib/python3.10/site-packages/ninja/operation.py", line 278, in _result_to_response
    return self.api.create_response(
  File "/home/adys/.cache/pypoetry/virtualenvs/fabrile-backend-fklT6p4J-py3.10/lib/python3.10/site-packages/ninja/main.py", line 453, in create_response
    content = self.renderer.render(request, data, response_status=status)
  File "/home/adys/.cache/pypoetry/virtualenvs/fabrile-backend-fklT6p4J-py3.10/lib/python3.10/site-packages/ninja/renderers.py", line 25, in render
    return json.dumps(data, cls=self.encoder_class, **self.json_dumps_params)
  File "/usr/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/adys/.cache/pypoetry/virtualenvs/fabrile-backend-fklT6p4J-py3.10/lib/python3.10/site-packages/ninja/responses.py", line 28, in default
    return super().default(o)
  File "/home/adys/.cache/pypoetry/virtualenvs/fabrile-backend-fklT6p4J-py3.10/lib/python3.10/site-packages/django/core/serializers/json.py", line 106, in default
    return super().default(o)
  File "/usr/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Url is not JSON serializable
@grigi grigi linked a pull request Dec 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant