Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 12 20:29
    manlix edited #3367
  • Jun 12 20:28
    manlix edited #3368
  • Jun 12 20:05
    github-actions[bot] commented #3367
  • Jun 12 20:05
    manlix labeled #3368
  • Jun 12 20:05
    manlix opened #3368
  • Jun 12 20:03
    codecov[bot] commented #3367
  • Jun 12 20:03
    codecov[bot] commented #3367
  • Jun 12 20:02
    manlix opened #3367
  • Jun 12 19:54
    justgoodin commented #1277
  • Jun 12 19:42
    zdytch closed #3366
  • Jun 12 19:41
    zdytch commented #3366
  • Jun 12 19:38
    ToGoBananas commented #884
  • Jun 12 19:36
    Kludex commented #3366
  • Jun 12 19:34
    zdytch opened #3366
  • Jun 12 19:34
    zdytch labeled #3366
  • Jun 12 16:22
    frankie567 commented #3344
  • Jun 12 16:19
    frankie567 commented #3344
  • Jun 12 12:36
    csudcy commented #884
  • Jun 12 11:26
    agropper commented #3344
  • Jun 12 11:11
    agropper commented #3344
nodarai
@nodarai
@Haider8
You have = instead of :
class CartDetail(BaseModel):
    item = PositiveInt
Jason Chiang
@N-index
haha
Kevin Morris
@kevr
Hello. I'm having some real trouble testing a FastAPI app which gives out secure and httponly cookies. Without the cookies, I can test the app perfectly fine and the cookies persist through requests. With those options added, the persistence no longer works (the test client's request does not seem to use the cookies for later requests). Does anybody have some experience with this who could point me in the right direction? I have Googled around quite a bit about this, but cannot find any relevant information.
Sorry, without the options*
junzisheng
@junzisheng
well
Kevin Morris
@kevr
Hm..
Kevin Morris
@kevr
Test send from gitter IRC.
Jason Chiang
@N-index
good morning
Kevin Morris
@kevr
Just posting this here again because I'm on the IRC gateway now and I'd like to keep track of the message.
I'm having trouble testing a FastAPI app which serves out secure and httponly (together) cookies. The test client request context does not seem to receive and persist them through calls. Is there a way to work around this, or a proper way to test this?
I have been searching on Google in regards to the issue, but finding absolutely nothing around.
Anthony Lukach
@alukach
Is there any way to do something like response_model_include but have it by dynamically set via query parameters? i.e. I want to support the user filtering output fields by a field query parameter. I suppose I could do return MyModel.include(specifiedFields) however i feel like there could be a cleaner way (i.e. leaning on FastAPI convenience magic)
Kevin Morris
@kevr
hm :\
Seems a bit odd that this doesn't work out of the box. I would think that secure/httponly would be pretty standard things.
Sascha Desch
@SDesch
This might be a somewhat unusual question, but how do I exit/crash an fastapi application from a route? I am currently writing a demo app for showing kubernetes to some co-workers and for that I'd like to simulate an application that crashes i.e. exits with some error code != 0. I already tried sys.exit('we should crash here'), raising BaseException etc. but fastapi just keeps going and refuses to die :D
Sascha Desch
@SDesch
Aside from my demo application I wonder whether this is a good default behavior? I've had a lot a trouble in the past with applications that kept going after reaching a invalid state and monitoring/diagnosing/fixing this was a pain and it would have been much easier if the whole application just had crashed so that the next layer e.g. kubernetes replica controller would have handled this.
Marcelo Trylesinski
@Kludex
how r u running the app?
Sascha Desch
@SDesch
using uvicorn
I realized that this probably isn't an issue with fastapi alone but rather with uvicorn/ whatever I use to run the app.
Marcelo Trylesinski
@Kludex
we have a PR opened about the exit code, not sure if it's related (I didn't check it yet)
but if you have a minimal code example, I can be more helpful
Diego Gaona
@diegocgaona

@diegocgaona Can you please help me here

@Haider8 . Sorry, I'm not an advanced user... but I would try to remove the * (don't know why are you using it in the function.
And try to change item = PositiveInt to item: Int
I really don't know if it is it, but, to me, seems that FastAPI is not understanding what are your parameters for the body.

Jason Devore
@devoredevelops:matrix.org
[m]
Shot in the dark here: are there any FastAPI extensions or other means by which I could provide a REST API for a pre-existing database? Something like sandman2 (https://github.com/jeffknupp/sandman2) or eve (https://github.com/pyeve/eve) is what I have in mind. My main use case is to support filtering, sorting, pagination, and (hopefully) searching on tables and views via query parameters from Snowflake and from MongoDB Atlas.
Rory Byrne
@synek
How can I override a class dependency, with __call__? Normally I could go client.app.dependency_overrides[the_function] = my_override but for class dependencies it needs to be an instance of the class, like client.app.dependency_overrides[instance_of_class] = my_override. I can't figure out how I could possibly have the class instance to pass in as a key. The docs don't seem to cover this use case either.
Haider Ali
@Haider8
Hey everyone, I want some suggestions regarding analytics for my FastAPI backend. I want to store information like, from where the request came, what was the response, what was the requested URL endpoint, how much time the server took to respond, what status code does the endpoint return, etc. I should also be able to visualize and filter all this data. Thanks in advance!
Moritz E. Beber
@Midnighter
Erol
@FrEaKmAn
hi all.. what is the best practice to access database (via sqlalchemy) in celery task? using Depends or?
Jason Chiang
@N-index
hi everybody, I'm caring about why fastapi does not has an automatic db migration tools just like flask(shell command), seems like we need to write Alembic by ourselves? sorry, is there an easier thing can be integrated to project?
Amidamaru Rookie
@thaodt

hi guys, is there anyone here use fastapi with gunicorn and uvicorn workers as 3rd option on production? i'm facing issue with worker timeouts when my app hit 600+ requests/sec.
After that, it made my rethinkdb server high cpu load and memory run out.
p/s: i use nginx as proxy (running behind Cloudflare loadbalancer).
I am serving my app like this gunicorn -k uvicorn.workers.UvicornWorker --config gunicorn_conf.py main:app --preload

And my gunicorn_conf.py:

loglevel = use_loglevel
workers = 6
bind =  
keepalive = 120
timeout = 1200
graceful_timeout = 180
Haider Ali
@Haider8
First I'll suggest to tune the workers number. Try decreasing and increasing and see how it works
Amidamaru Rookie
@thaodt

First I'll suggest to tune the workers number. Try decreasing and increasing and see how it works

hi @Haider8 i did it before. First my app started with 2 workers, then I increased it to 6 and added 2 new options to avoid timeout keepalive & timeout. Besides that, my nginx proxy conf also set options relating to timeout:

proxy_connect_timeout 75s;
proxy_read_timeout 300s;
proxy_send_timeout 300s;

But this issue is still there. I commented on the old thread tiangolo/fastapi#565 - last comment. I also used RethinkDB & had background tasks to insert data also.

Kevin Morris
@kevr
Sorry for the edit spam..
apteryxlabs
@apteryxlabs
Hey all - do you know if the @app.on_event('startup|shutdown') handlers function correctly if the tiangolo/uvicorn-gunicorn-fastapi-docker container is used with docker-compose? I noted just now the warning on the event handler page for fastAPI - would a fastapi container running in docker-compose qualify as a sub application?
I opened tiangolo/uvicorn-gunicorn-fastapi-docker#90 with a description of the code that's causing this headache, if you'd like more context.
fbpyr
@fbpyr:tchncs.de
[m]
@apteryxlabs: I used app.add_event_handler("startup", connect_to_mongo) to connect to mongo.. works fine over here in a docker-composed brython-fastapi-mongodb. but I built it from slim not from official fastapi:
FROM python:3.9.5-slim

RUN python3 -m pip install --no-cache-dir fastapi uvicorn motor aiofiles Jinja2
...
^^ but I also had the startup func working in the official. so should work there, too I guess. 🙂
apteryxlabs
@apteryxlabs
@fbpyr:tchncs.de Not working on my end, but simply declaring MONGO_CLIENT = AsyncIOMotorClient(settings.MONGO_URI) in main.py and importing that where I need it seems to work. I really doubt that's the canonical way to do things; would love a working demo mongo app from the fastapi team in the docs for reference!
Amidamaru Rookie
@thaodt
hi all, our gitter is quite silent. Do we have another chat channels more active?
Marcelo Trylesinski
@Kludex
yes
adrianzy
@adrianzy
How do I use pyinstaller with fastapi?
Sebastián Ramírez
@tiangolo

@/all

:rotating_light: Please upgrade to FastAPI 0.65.2 as soon as possible.

:lock: This version fixes a CSRF vulnerability in applications that use cookies to authenticate path operations that receive JSON payloads sent by browsers.

Thanks to Dima Boger for the report! :bow:

Details: https://github.com/tiangolo/fastapi/security/advisories/GHSA-8h2j-cgx8-6xv7

Amidamaru Rookie
@thaodt

@/all

:rotating_light: Please upgrade to FastAPI 0.65.2 as soon as possible.

:lock: This version fixes a CSRF vulnerability in applications that use cookies to authenticate path operations that receive JSON payloads sent by browsers.

Thanks to Dima Boger for the report! :bow:

Details: https://github.com/tiangolo/fastapi/security/advisories/GHSA-8h2j-cgx8-6xv7

bravo!

sowmy
@sowmywayne

I am new to cython and pydantic I try to compile my fastapi project in cython. when compiling the schemas and run the server response is empty. If I compile the project without schema its works fine. This my schema

class AuthenticationInDBBase(AuthenticationBase):
    idx: int
    is_default: int
    status: int

    class Config:
        orm_mode = True


class AuthenticationResponse(AuthenticationInDBBase):
    pass

plz anyone help me with how to declare schema for cython

Arne
@a-recknagel
Hi guys, how do I make a custom class openapi-consumable?
class Foo:
    pass

class Response(pydantic.BaseModel):
    foo: Foo  # won't work, how to update Foo so that it does?

@app.get("/")
def get_foo() -> Response:
    return Response(Foo())
Arne
@a-recknagel
I'd like to avoid having to make Foo inherit from pydantic.BaseModel, as long as there is a simple way to tell it "if fastapi asks, pretend you're this json here {...}"
lowercase00
@lowercase00
hey guys.
does anybody know how do I pass arguments from a decorator to the decorated route? I tried a few different approachs but couldn't make it work yet:
class Auth():
    def __init__(self, roles: Union[str, List[str]]):
        if type(roles) == str:
            self.list_of_roles = [roles.lower()]
        else:
            self.list_of_roles = [r.lower() for r in roles]
    def __call__(self, function):
        @functools.wraps(function)
        async def decorated(*args, **kwargs):
            permission = await self.__user_role_verify(*args, **kwargs)
            context = await self.__user_context(*args, **kwargs) >>>>>>>>>>>>>>> How to make this variable available at the route?
            if permission:
                response = await function(*args, **kwargs)
                return response
            else:
                raise HTTPException(status_code=401, detail="Unauthorized.")
        return decorated
@router.get("/accounts/")
@Auth
async def get_chart():
    context = >>>>>> How to use the context here?
    chart = await account_chart.fetch()
     return chart
dev-99
@dev-99

Hi folks,

I am loading a few models with the API. Is there a way to return an HTTP error code for requests made before application startup is complete? Currently, the requests are blocked waiting for the app to start.

Joshua Jamison
@codemation
@lowercase00 There are examples of how I do this in https://github.com/codemation/easyauth/blob/main/easyauth/router.py - mayble you will find the library nice to use, otherwise feel free to reference. Hope it helps
allomorphy
@allomorphy

:wave: Folks
I have an Endpoint working well to accept json in the body of the call like a simple list as per the documentation:
{"items": [{"name": "John"}, {"name": "Mary"}]}
This is with
async def process_measurements( items: ItemList):

However I have tried to adapt this to a more complex Object with Class deifntion and te function and have not been able to get to the answer quickly.

Here is the Object that we wish to parse.

 {
   "user":foo@gmail.com",
   "measurements":[
     {
       "name":"Glucose",
       "unit":"mMol",
       "value":"3.2",
       "date":"2021-06-12T15:18:45.984736445Z"
     },
     {
       "name":"Triglyceride",
       "unit":"mMol",
       "value":"3.2",
       "date":"2021-06-12T15:18:45.984736445Z"
     }
   ]
 }

Thanks for clues as to how I would do that.`