Skip to content

Replace FastAPI with LiteStar & JSON responses with HTMX#3000

Merged
spwoodcock merged 12 commits intodevfrom
feat/litestar
Jan 8, 2026
Merged

Replace FastAPI with LiteStar & JSON responses with HTMX#3000
spwoodcock merged 12 commits intodevfrom
feat/litestar

Conversation

@spwoodcock
Copy link
Copy Markdown
Member

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation
  • 🧑‍💻 Refactor
  • ✅ Test
  • 🤖 Build or CI
  • ❓ Other (please specify)

Describe this PR

  • Litestar isn't so different to FastAPI.
  • It has a lot more built in and some really nice patterns.
  • It's a bit stricted on return types on endpoints etc.
  • But one very nice thing is the DTO pattern where we no longer need so many copies of the same pydantic models. Instead we extend from the primary DbXXX model and use excludes= or includes= to determine which fields to included. These DTOs are only using for model serialisation on input and output from end points. All db queries use the primary db model.

For now I only did the migration, keeping all the same JSON endpoints for the existing frontend.

In future, we can start to add HTMX endpoints for HTMX responses instead of JSON, making the whole app a bit simpler into the future 🤞

Review Guide

Notes for the reviewer. How to test this change?

Checklist before requesting a review

[optional] What gif best describes this PR or how it makes you feel?

@spwoodcock spwoodcock self-assigned this Dec 23, 2025
@github-actions github-actions Bot added docs Improvements or additions to documentation enhancement New feature or request frontend Related to the frontend code backend Related to backend code migration Contains a DB migration dependency:area-splitter Requires updates in area-splitter dependency:osm-fieldwork Requires updates in osm-fieldwork tests Related to automated code tests labels Dec 23, 2025
@spwoodcock
Copy link
Copy Markdown
Member Author

#1685

@spwoodcock
Copy link
Copy Markdown
Member Author

Can we keep engine=calamine in the xlsx file reading? Its much more performant, as a driver written in rust

@Anuj-Gupta4
Copy link
Copy Markdown
Collaborator

Sure. I will add back.

@spwoodcock
Copy link
Copy Markdown
Member Author

I fixed the db pool usage during tests, so now we can run:

just test backend

Then fix the endpoint responses based on the output, e.g.

ERROR tests/test_projects_routes.py::test_delete_project - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
ERROR tests/test_projects_routes.py::test_upload_data_extracts - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
ERROR tests/test_projects_routes.py::test_generate_project_files - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
ERROR tests/test_projects_routes.py::test_update_project - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
ERROR tests/test_projects_routes.py::test_project_summaries - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
ERROR tests/test_projects_routes.py::test_project_by_id - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
ERROR tests/test_projects_routes.py::test_read_project - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
ERROR tests/test_projects_routes.py::test_update_and_download_project_form - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
ERROR tests/test_projects_routes.py::test_get_contributors - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
ERROR tests/test_projects_routes.py::test_add_new_project_admin - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
ERROR tests/test_projects_routes.py::test_create_entity - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
ERROR tests/test_projects_routes.py::test_download_project_boundary - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
ERROR tests/test_projects_routes.py::test_download_task_boundaries - TypeError: AbstractDTO.__init__() got an unexpected keyword argument 'sub'
FAILED tests/test_projects_routes.py::test_create_project_invalid - assert 400 == 422
FAILED tests/test_projects_routes.py::test_create_project_with_dup - assert 400 == 200
FAILED tests/test_projects_routes.py::test_valid_geojson_types[geojson_type0] - assert 400 == 200
FAILED tests/test_projects_routes.py::test_valid_geojson_types[geojson_type1] - assert 400 == 200
FAILED tests/test_projects_routes.py::test_valid_geojson_types[geojson_type2] - assert 400 == 200
FAILED tests/test_projects_routes.py::test_valid_geojson_types[geojson_type3] - assert 400 == 200
FAILED tests/test_projects_routes.py::test_valid_geojson_types[geojson_type4] - assert 400 == 200
FAILED tests/test_projects_routes.py::test_valid_geojson_types[geojson_type5] - assert 400 == 200
FAILED tests/test_projects_routes.py::test_invalid_geojson_types[geojson_type0] - assert 400 == 422
FAILED tests/test_projects_routes.py::test_invalid_geojson_types[geojson_type1] - assert 400 == 422
FAILED tests/test_projects_routes.py::test_project_hashtags[tag1, tag2, tag3-expected_output0] - assert 400 == 200
FAILED tests/test_projects_routes.py::test_project_hashtags[tag1   tag2    tag3-expected_output1] - assert 400 == 200
FAILED tests/test_projects_routes.py::test_project_hashtags[tag1, tag2 tag3    tag4-expected_output2] - assert 400 == 200
FAILED tests/test_projects_routes.py::test_project_hashtags[TAG1, tag2 #TAG3-expected_output3] - assert 400 == 200
FAILED tests/test_projects_routes.py::test_project_task_split - assert 201 == 200
15 failed, 38 passed, 13 errors in 160.86s (0:02:40)

@spwoodcock
Copy link
Copy Markdown
Member Author

@Anuj-Gupta4 I'm going to rebase on the latest dev, so if you have any unpushed commits, please stash them, reset this branch, then re-apply 🙏 Sorry for the hassle

@spwoodcock spwoodcock changed the title Replace FastAPI with LiteStar (including HTMX for future work) Replace FastAPI with LiteStar & JSON responses with HTMX Jan 7, 2026
@spwoodcock
Copy link
Copy Markdown
Member Author

A good way there! To be continued in a future PR 😄

@spwoodcock spwoodcock merged commit a0d56ed into dev Jan 8, 2026
2 of 4 checks passed
@spwoodcock spwoodcock deleted the feat/litestar branch January 8, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Related to backend code dependency:area-splitter Requires updates in area-splitter dependency:osm-fieldwork Requires updates in osm-fieldwork docs Improvements or additions to documentation enhancement New feature or request frontend Related to the frontend code migration Contains a DB migration tests Related to automated code tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants