netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Public demo: https://demo.netbox.dev
http://netboxlabs.com/oss/netbox/
Apache License 2.0
15.15k stars 2.46k forks source link

Clearing page length user preference breaks pagination #16173

Closed devon-mar closed 1 week ago

devon-mar commented 2 weeks ago

Deployment Type

Self-hosted

NetBox Version

v4.0.2

Python Version

3.10

Steps to Reproduce

  1. Create a new user account
  2. Visit a page that uses pagination. It should load properly.
  3. Open /user/preferences/ and click the "X" on Page length.
  4. Click Save.
  5. Visit the page in step 2. An error should occur.

Expected Behavior

The page should load without an error.

Observed Behavior

<class 'TypeError'>

'<' not supported between instances of 'int' and 'str'

Python version: 3.10.14
NetBox version: 4.0.2
Plugins: 
  netbox_demo: 0.5.0

I believe this is because the paginate.per_page preference is an empty string:

GET /api/users/config/

{
    "ui": {
        "htmx_navigation": ""
    },
    "locale": {
        "language": ""
    },
    "pagination": {
        "per_page": "",
        "placement": "bottom"
    },
    "data_format": "json"
}

Therefore, per_page is set to "" instead of config.PAGINATE_COUNT: https://github.com/netbox-community/netbox/blob/4b2f26a8002a8f01e186211c648768892cc199c8/netbox/utilities/paginator.py#L90

devon-mar commented 2 weeks ago

Can I be assigned to this? I have a PR ready to go.