silnrsi / langfontfinder

The Find A Font service code
Other
3 stars 2 forks source link

Error executing `lib/langfontfinder/api.py` #8

Closed imnasnainaec closed 6 months ago

imnasnainaec commented 1 year ago

Here's the error

Traceback (most recent call last):
  File "C:\Users\danie\imnasnainaec\langfontfinder\lib\langfontfinder\api.py", line 33, in <module>
    async def lang(response: Response, ltag: str = Path("", description="Language tag")):
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\danie\imnasnainaec\langfontfinder\venv\Lib\site-packages\fastapi\param_functions.py", line 54, in Path
    return params.Path(
           ^^^^^^^^^^^^
  File "C:\Users\danie\imnasnainaec\langfontfinder\venv\Lib\site-packages\fastapi\params.py", line 178, in __init__
    assert default is ..., "Path parameters cannot have a default value"
           ^^^^^^^^^^^^^^
AssertionError: Path parameters cannot have a default value

I'm on Windows 11 using Python 3.11 with the following libraries loaded:

annotated-types==0.5.0
anyio==3.7.1
certifi==2023.7.22
click==8.1.6
colorama==0.4.6
fastapi==0.101.1
h11==0.14.0
httpcore==0.17.3
httpx==0.24.1
idna==3.4
langtag @ git+https://github.com/silnrsi/langtags@master
pydantic==2.1.1
pydantic-core==2.4.0
sniffio==1.3.0
starlette==0.27.0
typing-extensions==4.7.1
uvicorn==0.23.2
imnasnainaec commented 1 year ago

In https://github.com/silnrsi/langfontfinder/blob/main/lib/langfontfinder/api.py#L33-L41, changing

... eliminated the error, so when I run api.py I get:

INFO:     Started server process [6636]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

But then http://127.0.0.1:8000 only shows {"detail":"Not Found"} so I don't know if that correctly fixes the issue.

imnasnainaec commented 1 year ago

Potential pr with that change: https://github.com/silnrsi/langfontfinder/compare/main...imnasnainaec:langfontfinder:lib-langfontfinder-apy-py-path-default

imnasnainaec commented 1 year ago

@DavidLRowe When running lib/langfontfinder/api.py, is the expected default to see {"detail":"Not Found"} at http://127.0.0.1:8000?

DavidLRowe commented 1 year ago

@mhosken Can you comment on this issue when you have the time?

mhosken commented 1 year ago

My guess this comes from building on sand. Sigh. I so liked the conservative nature of python in the past. Ah well. I'm quite happy seeing this change so long as it doesn't break the server.

mhosken commented 12 months ago

Pulling @tim-eves to check this isn't going to break production

DavidLRowe commented 12 months ago

@imnasnainaec Thanks for reporting this. It seems to be due to you using a later version of fastapi than we currently have. @tim-eves plans to implement your suggestion for changes, then include a version in the requirements.txt in order to catch any similar changes in future.

The {"detail":"Not Found"} return is expected. It is essentially a text rendering of the 404 "Not Found" response that happens when there's a missing parameter.

Thanks again for reporting this.

DavidLRowe commented 12 months ago

I'll wait to close this until the fix is actually in place.

tim-eves commented 6 months ago

Fixed in GH-15, in turns out this was always a problem because Path() parameters are always required so the default value is nonsensical for a Path. The newer version just got stricter about not allowing it.