AnswerDotAI / AnswerDotAI/fasthtml
[BUG] Route Content Not Updating When Redefined with Different Function Name in Jupyter Notebook
- Dominant language
- Jupyter Notebook
- Stars
- 7k
- Forks
- 319
- Avg merge
- 28m
- Merged PRs (30d)
- 3
Description
### Description
When attempting to redefine the same route in Jupyter Notebook using a different function name, such as specifying the HTTP verb (`get()`) and the route (`change()`), the content of the route does not update as expected.
### Issue
When running the following code in a cell, the browser correctly displays "Change is good!":
```python
@rt("/change")
def get():
return P("Change is good!")
```
However, when I attempt to redefine the same route with the function name matching the route in the next cell, as shown below, the browser still displays "Change is good!" instead of the updated content:
```python
@rt("/change")
def change():
return P("Change is better! - Without specifying the HTTP verb as 'get()'")
```
I checked the `app.routes` to investigate the issue, and I found that the "/change" route is being registered twice with the same method (`GET`), as shown in the output:
```
[Route(path='/', name='get', methods=['GET', 'HEAD']),
Route(path='/change', name='get', methods=['GET', 'HEAD']),
Route(path='/change', name='change', methods=['GET', 'HEAD', 'POST'])]
```
### Expected Behavior
The route should pick the most recently defined handler for the route `/change` instead of retaining the previous one. The issue may be that duplicate routes with the same method (`GET`) are not being handled correctly.
Is this behavior expected, or is this a bug?
### Environment Information
Please provide the following version information:
- fastlite version: 0.1.1
- fastcore version: 1.7.28
- fasthtml version: 0.11.0
### Confirmation
Please confirm the following:
- [x] I have read the FAQ (https://docs.fastht.ml/explains/faq.html)
- [x] I have provided a minimal reproducible example
- [x] I have included the versions of fastlite, fastcore, and fasthtml
- [x] I understand that this is a volunteer open source project with no commercial support.
Contributor guide
Research direction
Start with the two-cell Jupyter Notebook example and inspect the resulting app.routes entries for /change. Reproduce the duplicate GET route behavior, then verify that the most recently defined handler serves the updated content.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, python
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100