Repository navigation
Closed
Description
Added APItally to a working DRF back-end. FWIW, it also uses drf_spectacular and ReDoc (which all work fine).
- Added APItally via Poetry:
poetry add "apitally[django_rest_framework]" - Added middleware:
MIDDLEWARE = [
"apitally.django.ApitallyMiddleware",
# Other middleware ...
]
- Created the App on the APItally back-end and got the settings:
APITALLY_MIDDLEWARE = {
"client_id": "{client-id}",
"env": "dev"
}
- Reset the whole application, just to be safe (re-creates all database settings, migrations, etc.)
- Went to bring up the app and got these errors (path's edited):
Failed to get OpenAPI schema
Traceback (most recent call last):
File ".../.venv/lib/python3.12/site-packages/apitally/django.py", line 198, in _get_startup_data
data["openapi"] = _get_openapi(urlconfs)
^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.12/site-packages/apitally/django.py", line 210, in _get_openapi
drf_schema = _get_drf_schema(urlconfs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.12/site-packages/apitally/django.py", line 260, in _get_drf_schema
schema = generator.get_schema()
^^^^^^^^^^^^^^^^^^^^^^
File .../.venv/lib/python3.12/site-packages/rest_framework/schemas/openapi.py", line 80, in get_schema
operation = view.schema.get_operation(path, method)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: AutoSchema.get_operation() missing 3 required positional arguments: 'path_prefix', 'method', and 'registry'
- The schema seems to partly show up in the APItally dashboard, but it's hard to tell from error messages where it stops.
- Commenting out APItally from the MIDDLEWARE settings, then re-running again. The errors go away and everything works.
- This is for a
devenvironment. Everything is running locally on top of SQLite. Also have variations that run inside Docker, and another that pushes everything out to AWS serverless, but would like to get APItally to run locally before moving on to others.
This is with:
- Python 3.12.2 on a Mac. Also:
django = "^5.0.7"
djangorestframework = "^3.15.2"
drf-spectacular = "^0.27.2"
sentry-sdk = {extras = ["django"], version = "^2.11.0"}
apitally = {extras = ["django-rest-framework"], version = "^0.11.1"}
...
Any suggestions appreciated.
Metadata
Metadata
Assignees
Labels
No labels
Activity
browniebroke commentedon Jul 28, 2024
This typically happens when the generating the open API schema using DRF methods on endpoints where DRF-spectacular AutoSchema is set. The stack trace points at this line:
https://github.com/apitally/apitally-py/blob/4fe5298e7cd7892f5368e29acb1a86e0593dcacd/apitally/django.py#L260
They use DRF SchemaGenerator, but spectacular has its own one https://github.com/tfranzel/drf-spectacular/blob/cc916372a0e3fafc3af48f94dd1a985f5fc466e9/drf_spectacular/generators.py#L102
IMO this is more an issue for APItally than DRF, they could detect whether spectacular is installed and use the appropriate generator if needed.
rubyazz commentedon Jul 29, 2024
its better to use https://drf-yasg.readthedocs.io/en/stable/readme.html