Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve route ambiguity for /tasks/activity endpoint #1924

Merged
merged 2 commits into from
Nov 29, 2024

Conversation

Sujanadh
Copy link
Contributor

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

  • πŸ• Feature
  • πŸ› Bug Fix
  • πŸ“ Documentation
  • πŸ§‘β€πŸ’» Refactor
  • βœ… Test
  • πŸ€– Build or CI
  • ❓ Other (please specify)

Related Issue

{
  "errors": [
    {
      "loc": [
        "path",
        "task_id"
      ],
      "msg": "Input should be a valid integer, unable to parse string as an integer",
      "error": "Input should be a valid integer, unable to parse string as an integer['path', 'task_id']"
    }
  ]
}

Describe this PR

This PR resolves a routing issue in the /tasks/activity endpoint. A trailing slash (/) was added to the endpoint definition to ensure unambiguous route matching.

Previously, the /tasks/activity route conflicted with the dynamic route /tasks/{task_id}, causing the framework to misinterpret activity as a task_id, resulting in validation errors.

Screenshots

N/A

Alternative Approaches Considered

Did you attempt any other approaches that are not documented in code?

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?

@Sujanadh Sujanadh self-assigned this Nov 28, 2024
@github-actions github-actions bot added bug Something isn't working frontend Related to frontend code backend Related to backend code labels Nov 28, 2024
@Sujanadh Sujanadh marked this pull request as draft November 28, 2024 09:41
@spwoodcock
Copy link
Member

spwoodcock commented Nov 28, 2024

One thing that is key to account for here is the route ordering in the xxx_routes.py file!

For example a /projects/{project_id} endpoint should be defined as late as possible,
then an endpoint like /projects/do-something defined above it.

The routes are resolved in order in the file, so if they were the other way around then FastAPI would try to load: /projects/do-something, but complain it can't find a project with id do-something as do-something would be passed as the {project_id}.

Something like this could be happening here πŸ˜„

@Sujanadh
Copy link
Contributor Author

Yes, you are right. The actual issue is due to the ordering of endpoints. In addition to ordering, we need to define distinct endpoints with trailing slash '/' in every endpoint. What else would be the best approach to avoid this kind of issue? @spwoodcock Yes, we can maintain ordering and place endpoints with placeholders in the path following other endpoints.

@spwoodcock
Copy link
Member

Yes, you are right. The actual issue is due to the ordering of endpoints. In addition to ordering, we need to define distinct endpoints with trailing slash '/' in every endpoint. What else would be the best approach to avoid this kind of issue? @spwoodcock Yes, we can maintain ordering and place endpoints with placeholders in the path following other endpoints.

We should be sure to not use a trailing slash for endpoints, but instead ensure the ordering is correct πŸ‘

But note this is only ordering per router, so an alternative could be a different grouping of endpoints:

  • We could better adhere to rest principals by putting nested tasks under the projects router. /projects/1/tasks/1
  • Perhaps have an events router, using query params. /events?project_id=1&task_id=1
  • Remove 'action' based endpoints, replacing them with a more generic version. For example on the organisations router, don't have a /approve endpoint, but instead a generic /status endpoint where we post the approved status.
  • Loads of options here for improvement...

I digress πŸ˜… In summary, for now let's just fix the ordering!

@spwoodcock spwoodcock merged commit 4cf25a9 into development Nov 29, 2024
8 of 9 checks passed
@spwoodcock spwoodcock deleted the fix/task-activity branch November 29, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Related to backend code bug Something isn't working frontend Related to frontend code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants