-
-
Notifications
You must be signed in to change notification settings - Fork 256
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
Non-standard record IDs can cause a record not found error #3368
Comments
Hey @davidlormor thank you for such a detailed issue. I think we could insert that constrain somewhere around here https://github.com/avo-hq/avo/blob/main/lib/avo/dynamic_router.rb#L7 Based on your research, are there any potential consequences of applying this constraint, and why might it not be set as the default for rails? |
Thanks for the quick reply @Paul-Bob! I think that would make sense as a quick workaround, although you'd probably need to apply it around the whole route file, due to the fact that there are several routes at that reference the As far as consequences, it seems like the main concern, is that it opens up some issues around route parsing and possibly security (e.g. if you had a key like In the Avo use case, I would imagine those concerns are probably pretty negligible. A few thoughts I had:
One thing I noticed is the current dynamic routing introduces a bug that prevents a constraint from being passed down to the resource routes even when manually adding it to the Avo engine routes config. I'm going to open a PR shortly with a fix for that, as the current setup appears to go against some of the recommendations in the Rails routing guide. |
Added #3369 as a preemptive fix to the resource route loading that would be required for any solution to applying external constraints to the routes. |
@davidlormor I just committed this 41ee230 to fix the routes on that PR accordingly to rails docs and what you suggested on the PR. This change makes sense, thanks for exposing it. However, from my tests, the constraints are still not passed down to the resource routes. I've tried with: mount Avo::Engine, at: Avo.configuration.root_path, constraints: { id: /[^\/]+/ } And constraints id: /[^\/]+/ do
mount Avo::Engine, at: Avo.configuration.root_path
end On the other side applying those constraints around the constraints id: /[^\/]+/ do
draw(:dynamic_routes)
end |
@Paul-Bob thanks for taking a look! Yeah, I didn't expect #3369 to fix the issue entirely, but from my testing locally, that fix will ensure that wrapping the entire routes block with a constraint will properly pass the constraint to all routes. Without that fix, a constraint around the entire routes block wouldn't get passed to the dynamic routes because of the extra call to As mentioned in the PR comment after it was merged, I've discovered the scope of our issue is actually a bit bigger because we also have some tables that have composite primary keys. I'll circle back soon with additional details and thoughts on how Avo might be able to handle it gracefully. Thanks for the help and the quick turnaround on the PR! |
This issue has been marked as stale because there was no activity for the past 15 days. |
@davidlormor have you found any workaround? |
Related discussion: #3451 |
Describe the bug
Avo can't handle non-standard primary keys/IDs that don't follow Rails' out-of-the-box conventions (e.g. periods in a string-based ID). Rails documents how to work around this via constraints in their guides. Unfortunately, it appears that segment-level constraints cannot be passed down to routes in a mounted engine.
Steps to Reproduce
Steps to reproduce the behavior:
Expected behavior & Actual behavior
I would expect the book to be rendered via Avo, but instead I get a 500 page. Inspecting the Rails server output, it appears that the book cannot be found, due to an incorrectly parsed ID param. The request params are logged as
params: { id: "11-2003" }
(note the missing content starting at the.
character).According to the Rails guides, this issue can be solved via a constraint:
Unfortunately, it appears that because the constraint applies at the route segment level, it is not passed to the Rails engine (I've confirmed this on a separate example engine). I've logged a question on the Rails discussion board to see if anything can/should be done at the Rails level, since this affects all engines, not just Avo.
Models and resource files
See above for setup.
System configuration
Avo version: 3.13.7
Rails version: 8.1.0.alpha
Ruby version: 3.3.5
License type:
Are you using Avo monkey patches, overriding views or view components?
Screenshots or screen recordings
Additional context
Impact
Urgency
The text was updated successfully, but these errors were encountered: