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
Issue with "resource/" and "resource" routing, triggering twice #109
Comments
@NinoFloris I'd like to contribute by adding some tests. Maybe, as a step towards solving, I could add a test to reproduce this issue. Is this bug specifically related to controllers? Do you have an example somewhere that I could review? |
@NinoFloris the controller unit tests include tests for create and update. In the tests , the create action is only called once, and the update action is only called once. I created a test project with the following controller: type Foo = { Name: string }
let api = controller {
create (fun ctx -> ctx.GetLogger().LogInformation("create"); Controller.json ctx {Name = "foo" })
update (fun ctx name -> ctx.GetLogger().LogInformation("update"); Controller.json ctx {Name = name} )
} And I do not see "update" logged when I hit the POST endpoint. |
It's about the plugs |
@NinoFloris Can you please provide more information as to what is broken? A broken code example would be lovely. |
@StachuDotNet I was able to reproduce the issue locally, and have a unit test that causes the issue. I have a tentative fix. I’ll push up the failing test this evening. |
Thanks @jeremyabbott. Sorry I'm currently swamped, a repro could have helped |
@StachuDotNet here's my branch with a failing test that indicates what's happening. Here's a description of what's happening from the commit I made:
I'm planning on looking at it some more tomorrow night (or later this evening...) |
@StachuDotNet actually I think this happens without update. So my explanation above is wrong. If you look at this commit, you'll see where I've commented out the update tests, and the create test still fails. We add the handlers twice for Create at lines 234/235 of Controller.fs (my branch). The plug is applied to each handler, so my best guess is that each handler is getting evaluated, but only the second handler is executed. When I comment out 234, the test passes again. |
It does happen if you make a POST and you have and Update action defined. This is because of line 234 as well. If we make a POST to resource/1 we we hit the plug added by 234 for [Create] because we haven't added the route until after the plug is applied. I think the intent should be for routes/verb pairs should be synonymous with the corresponding action name. So create = POST "/" (or ""), and update = POST "/{id}" or PUT "/{id}. This will happen in any scenario where we add two handlers with different paths for the same action. |
@NinoFloris @StachuDotNet I think I figured it out. PR here which prevents plugs from firing twice, and also tests controllers to make sure they continue to work as expected. |
Fixed by #143 |
Best seen with having a create and update handler, try to POST to "/resource/" two plugs will fire, first for create then for update.
This is baddd...
The text was updated successfully, but these errors were encountered: