You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
however the data returned is simply an array of items, no additional pagination properties. They do appear if I manually supply a limit= parameter, but the openapi spec does not seem to reflect that.
Steps to Reproduce
Access any API list endpoint without providing a limit
Expected behaviour
OpenAPI schema should match the server output
Deployment Method
Docker
Package
Bare metal
Other - added info in Steps to Reproduce
Version Information
0.17.6
Please verify if you can reproduce this bug on the demo site.
I've tried with category tree, category list, and parts list so far... Could try a few more...
admin_config_list fails if pagination is requested
Traceback (most recent call last):
File "/root/.local/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/rest_framework/generics.py", line 199, in get
return self.list(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/rest_framework/mixins.py", line 40, in list
page = self.paginate_queryset(queryset)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/rest_framework/generics.py", line 171, in paginate_queryset
return self.paginator.paginate_queryset(queryset, self.request, view=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/lib/python3.11/site-packages/rest_framework/pagination.py", line 395, in paginate_queryset
return list(queryset[self.offset:self.offset + self.limit])
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'slice'
attachment_list behaves as outline in the ticket background_task_failed_list same background_task_pending_list same barcode_history_list does not paginate, all results are just an array (however it might be affected by the setting for collection of scanned barcodes). bom_list same as outlined in the ticket bom_substitute_list same build_list same build_item_list same build_line_list same company_list same
I could go on, but the pattern seems to be consistent
Any way to drive the output schema based on the presence of limit
parameter?
I don't want to break ui, but I want my codegen to generate something the
compiler is happy with...
Also, some fields are not even described in the swagger, e.g. I was trying
to get parts based on category, it works if I pass the parameter over the
query string, but the codegen version doesn't have it...
Also, some fields are not even described in the swagger, e.g. I was trying to get parts based on category, it works if I pass the parameter over the query string, but the codegen version doesn't have it...
There are some legacy filtering attributes which are not exposed to the auto-doc based on how we do the filtering. I am working (gradually) to migrate to the "proper" approach - so that they are documented correctly. If you find any instances like this please raise separate issues so that we can tackle them individually.
If you're willing to modify the api.yaml before running your code generator you can easily set the limit attribute to be required with this sed 1-liner:
sed -i -z -E 's/name: (limit\W+)required: false/name: \1required: true/g' api.yaml
Alternately, you can regenerate the schema without paging by setting up a dev environment, modifying src/backend/InvenTree/InvenTree/settings.py to change DEFAULT_PAGINATION_CLASS to None, then running invoke dev.schema --ignore-warnings --filename api.yaml
Regarding setting a oneOf discriminator, it may be possible to annotate with some variation of @extend_schema to add a PolymorphicProxySerializer to generate a oneOf discriminator offering paginated object / list of objects.
I just can't figure out where that would go considering that pagination is set by configuration.
The question is, why do we have such a shape changing api based on parameters? Wound it be the cleanest to remove that as a braking Ching for 1.0.0? So that we always return the paginated way and remove the full response entirely?
The question is, why do we have such a shape changing api based on parameters?
Let's say my lack of experience and clear design goals when I first started developing the API ;)
There are four main areas where the API is "mutated" based on parameters in an undocumented fashion:
Pagination
Most (but not all) list endpoints can be passed pagination parameters to return a paginated queryset. By default, you get the whole list.
This is "non standard" for sure - but I kind of like the flexibility it allows. The client can define whether they want a paginated response or not - for example the tables enforce pagination, but some elements (like fetching all settings) you want to ensure that you capture everything in a single query.
Not sure how best to proceed here - potentially I think I'd like to see it documented more clearly but retain the current behaviour.
Filtering
Filtering the querysets via query params can have some "hidden" features. That is, query parameters which are not exposed to the API schema because they are hard-coded into the filter_queryset method. This is becoming less of a problem as I have been working to reduce this approach. Now, we use the django-rest-framework-filters to define filters which are exposed to the API auto-doc.
There are still some to transfer across but it's getting there!
Related Fields
This is the most "inconsistent" part of the API - and one I'd like to address (somehow). At multiple points across the API we have the ability to specify which "detail" attributes are annotated against the serializer.
For example, you can do /api/stock/?part_detail=true which will add in the part_detail field against each stock item. However, there is no auto-doc for this.
Additionally, this is not consistent across the API. Some x_detail fields are always there, some are default-on, some are default-off. There is not really a clear methodology around these choices to be honest.
The reason for this approach is to reduce serialization burden on the server when it is not needed. In some cases, you don't need the part_detail (or whatever) against a particular dataset. A good example would be when fetching all stock items for a given part. You already have the part information, and it's going to be the same for every stock item, so why waste time serializing it?
However, potentially an argument could be made that it is better to reduce the complexity of the API calls, at the expense of query time. Happy to discuss this further.
Brief Serializers
Finally, at different points in the API we have the concept of a "brief" version of a particular serializer. This has a reduced set of fields allowing "important" data to be serialized into an x_detail field. Might be worth considering removing these in favor of a single defined serializer for each model.
In summary, there are a lot of legacy implementations which are just baggage from my journey from embedded software to web development ;) Any of these are up for change, let's discuss :)
Do not get me wrong, this was not meant in any offensive way, every project starts small onetime. Awesome what you built up with inventree. It was just some idea I'd liked to throw in which may solve that issue, and now with the v1.0 release this may be the right time. Happy to discuss this @matmair wasn't that also somwthing that you like'd to have, non shape changing API endpoint responses?
Activity
SchrodingersGat commentedon Feb 27, 2025
@vsviridov an interesting problem. Have you tested this across multiple API endpoints? Or only the part-category-tree endpoint?
vsviridov commentedon Feb 27, 2025
I've tried with category tree, category list, and parts list so far... Could try a few more...
admin_config_listfails if pagination is requestedattachment_listbehaves as outline in the ticketbackground_task_failed_listsamebackground_task_pending_listsamebarcode_history_listdoes not paginate, all results are just an array (however it might be affected by the setting for collection of scanned barcodes).bom_listsame as outlined in the ticketbom_substitute_listsamebuild_listsamebuild_item_listsamebuild_line_listsamecompany_listsameI could go on, but the pattern seems to be consistent
SchrodingersGat commentedon Mar 1, 2025
I have a fix for the config list here - #9210
Regarding the overarching issue - it looks like we are missing the
PAGE_SIZEattribute in ourREST_FRAMEWORKsetup:InvenTree/src/backend/InvenTree/InvenTree/settings.py
Line 524 in 3ff5078
If I add
PAGE_SIZE: 25to this setup dict, then the default behaviour is to paginate.Currently, if you supply a
?limit=<x>query parameter, the API data will paginate. If not supplied, you get all the items.Changing this behaviour will break a lot of front-end features which expect a full dataset.
Alternatively the tables (and other places where large datasets are expected) require the pagination functionality to work as expected.
Not sure how to consolidate all this.
vsviridov commentedon Mar 1, 2025
SchrodingersGat commentedon Mar 1, 2025
There are some legacy filtering attributes which are not exposed to the auto-doc based on how we do the filtering. I am working (gradually) to migrate to the "proper" approach - so that they are documented correctly. If you find any instances like this please raise separate issues so that we can tackle them individually.
SchrodingersGat commentedon Mar 1, 2025
I'm not sure - perhaps if you can find a way to achieve this nicely, I'd happily review a PR :)
vsviridov commentedon Mar 1, 2025
1337joe commentedon Mar 3, 2025
I'll chime in since I've been poking at this too.
If you're willing to modify the api.yaml before running your code generator you can easily set the limit attribute to be required with this sed 1-liner:
sed -i -z -E 's/name: (limit\W+)required: false/name: \1required: true/g' api.yamlAlternately, you can regenerate the schema without paging by setting up a dev environment, modifying
src/backend/InvenTree/InvenTree/settings.pyto changeDEFAULT_PAGINATION_CLASStoNone, then runninginvoke dev.schema --ignore-warnings --filename api.yaml1337joe commentedon Mar 15, 2025
Regarding setting a oneOf discriminator, it may be possible to annotate with some variation of
@extend_schemato add aPolymorphicProxySerializerto generate aoneOfdiscriminator offering paginated object / list of objects.I just can't figure out where that would go considering that pagination is set by configuration.
wolflu05 commentedon Mar 15, 2025
The question is, why do we have such a shape changing api based on parameters? Wound it be the cleanest to remove that as a braking Ching for 1.0.0? So that we always return the paginated way and remove the full response entirely?
SchrodingersGat commentedon Mar 15, 2025
Let's say my lack of experience and clear design goals when I first started developing the API ;)
There are four main areas where the API is "mutated" based on parameters in an undocumented fashion:
Pagination
Most (but not all) list endpoints can be passed pagination parameters to return a paginated queryset. By default, you get the whole list.
This is "non standard" for sure - but I kind of like the flexibility it allows. The client can define whether they want a paginated response or not - for example the tables enforce pagination, but some elements (like fetching all settings) you want to ensure that you capture everything in a single query.
Not sure how best to proceed here - potentially I think I'd like to see it documented more clearly but retain the current behaviour.
Filtering
Filtering the querysets via query params can have some "hidden" features. That is, query parameters which are not exposed to the API schema because they are hard-coded into the
filter_querysetmethod. This is becoming less of a problem as I have been working to reduce this approach. Now, we use the django-rest-framework-filters to define filters which are exposed to the API auto-doc.There are still some to transfer across but it's getting there!
Related Fields
This is the most "inconsistent" part of the API - and one I'd like to address (somehow). At multiple points across the API we have the ability to specify which "detail" attributes are annotated against the serializer.
For example, you can do
/api/stock/?part_detail=truewhich will add in thepart_detailfield against each stock item. However, there is no auto-doc for this.Additionally, this is not consistent across the API. Some
x_detailfields are always there, some are default-on, some are default-off. There is not really a clear methodology around these choices to be honest.The reason for this approach is to reduce serialization burden on the server when it is not needed. In some cases, you don't need the
part_detail(or whatever) against a particular dataset. A good example would be when fetching all stock items for a given part. You already have the part information, and it's going to be the same for every stock item, so why waste time serializing it?However, potentially an argument could be made that it is better to reduce the complexity of the API calls, at the expense of query time. Happy to discuss this further.
Brief Serializers
Finally, at different points in the API we have the concept of a "brief" version of a particular serializer. This has a reduced set of fields allowing "important" data to be serialized into an
x_detailfield. Might be worth considering removing these in favor of a single defined serializer for each model.In summary, there are a lot of legacy implementations which are just baggage from my journey from embedded software to web development ;) Any of these are up for change, let's discuss :)
wolflu05 commentedon Mar 16, 2025
Do not get me wrong, this was not meant in any offensive way, every project starts small onetime. Awesome what you built up with inventree. It was just some idea I'd liked to throw in which may solve that issue, and now with the v1.0 release this may be the right time. Happy to discuss this @matmair wasn't that also somwthing that you like'd to have, non shape changing API endpoint responses?
Require limit parameter to ensure paginated results
matmair commentedon Mar 23, 2025
Non-shape changing APIs would make things a lot easier - would be breaking probably.
matmair commentedon Apr 18, 2025
Also see #9481