Skip to content

chore: added API validation for numeric values#826

Open
Stellatsuu wants to merge 12 commits intoDIRACGrid:mainfrom
Stellatsuu:endpoint_input_validation
Open

chore: added API validation for numeric values#826
Stellatsuu wants to merge 12 commits intoDIRACGrid:mainfrom
Stellatsuu:endpoint_input_validation

Conversation

@Stellatsuu
Copy link
Contributor

Closes: #506

Changes:

  • added min-max validation in per_page query value /jobs/search
  • added min validation in page query value of /jobs/search
  • updated tests

Comments:
I can't reproduce this error from the issue, I think it has been fixed somewhere else:

In the job query for example pymysql.err.ProgrammingError, setting page number > 100

I don't really see other cases here for numeric values. Most numeric values are job_ids that are stored in DB and can't be validated from the FastAPI schemas, same for the page max value that can't be validated since it's based on DB, anyways, a page value out of bound will return a 416 error = no jobs found at this page value (might be why I can't reproduce the error above).

As for strings values, I did not find any relevant cases, most relevant ones does already have a validation (such as max_length and regex)

@Stellatsuu Stellatsuu self-assigned this Mar 10, 2026
Copy link
Contributor

@aldbr aldbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Stellatsuu!
About the client generation, are you using the same version locally than the one in the CI? (normally yes, but worth checking)

@chrisburr
Copy link
Member

This works as expected for me with changes needing to be pushed.

Can you show the output of:

git status
git show
pixi run -e diracx-generate-client generate-client
pixi run -e gubbins-generate-client generate-client

@Stellatsuu Stellatsuu force-pushed the endpoint_input_validation branch from 49bfbfe to b073714 Compare March 19, 2026 10:27
@Stellatsuu
Copy link
Contributor Author

Stellatsuu commented Mar 19, 2026

@chrisburr

> git status
On branch endpoint_input_validation
Your branch is up to date with 'origin/endpoint_input_validation'.

nothing to commit, working tree clean

> git show
show.patch

> git diff origin/main
diff.patch

> pixi run -e diracx-generate-client generate-client 
✨ Pixi task (generate-client in diracx-generate-client): python -m diracx.testing.client_generation: (Generate the API clients for diracx-client)                                  ⠁Ensuring autorest is installed by running npm install -g autorest@3.8.0

changed 1 package in 515ms
Generating client for diracx
Running: /Users/stella/Desktop/diracx/.pixi/envs/diracx-generate-client/bin/python -m pytest -pdiracx.testing --import-mode=importlib --no-cov --regenerate-client=diracx /Users/stella/Desktop/diracx/diracx-testing/src/diracx/testing/client_generation_pytest.py
=============================================================================== test session starts ================================================================================
platform darwin -- Python 3.11.14, pytest-8.4.2, pluggy-1.6.0 -- /Users/stella/Desktop/diracx/.pixi/envs/diracx-generate-client/bin/python
cachedir: .pytest_cache
rootdir: /Users/stella/Desktop/diracx
configfile: pyproject.toml
plugins: anyio-4.12.1, lazy-fixtures-1.4.0, xdist-3.8.0, httpx-0.35.0, github-actions-annotate-failures-0.3.0, asyncio-1.3.0, cov-7.0.0
asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 1 item                                                                                                                                                                   

diracx-testing/src/diracx/testing/client_generation_pytest.py::test_regenerate_client PASSED                                                                                 [100%]

================================================================================ 1 passed in 20.35s ================================================================================
> pixi run -e gubbins-generate-client generate-client
✨ Pixi task (generate-client in gubbins-generate-client): python -m diracx.testing.client_generation: (Generate the API clients for diracx-client)                                 ⠁Ensuring autorest is installed by running npm install -g autorest@3.8.0

changed 1 package in 798ms
Generating client for gubbins
Running: /Users/stella/Desktop/diracx/.pixi/envs/gubbins-generate-client/bin/python -m pytest -pdiracx.testing --import-mode=importlib --no-cov --regenerate-client=gubbins /Users/stella/Desktop/diracx/diracx-testing/src/diracx/testing/client_generation_pytest.py
=============================================================================== test session starts ================================================================================
platform darwin -- Python 3.11.14, pytest-8.4.2, pluggy-1.6.0 -- /Users/stella/Desktop/diracx/.pixi/envs/gubbins-generate-client/bin/python
cachedir: .pytest_cache
rootdir: /Users/stella/Desktop/diracx
configfile: pyproject.toml
plugins: anyio-4.12.1, lazy-fixtures-1.4.0, xdist-3.8.0, httpx-0.35.0, github-actions-annotate-failures-0.3.0, asyncio-1.3.0, cov-7.0.0
asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 1 item                                                                                                                                                                   

diracx-testing/src/diracx/testing/client_generation_pytest.py::test_regenerate_client PASSED                                                                                 [100%]

================================================================================ 1 passed in 20.81s ================================================================================

Branch is rebased on main :

image

@aldbr
Copy link
Contributor

aldbr commented Mar 19, 2026

Looks like you solved your issue! What did you do?
Is it ready to be reviewed now?

@Stellatsuu
Copy link
Contributor Author

I had issues with my pixi, it is ready now

@Stellatsuu Stellatsuu marked this pull request as ready for review March 19, 2026 13:12
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 this pull request may close these issues.

Input validation is required to avoid 500 errors

3 participants