Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 15:37
    falkben commented #2892
  • 14:22
    Kludex commented #2907
  • 14:09
    hesummerzh commented #2907
  • 13:51
    snow6oy commented #911
  • 13:10
    Suyoung789 edited #2908
  • 13:09
    github-actions[bot] commented #2908
  • 13:08
    codecov[bot] commented #2908
  • 13:08
    codecov[bot] commented #2908
  • 13:06
    codecov[bot] commented #2908
  • 13:06
    codecov[bot] commented #2908
  • 13:06
    Suyoung789 synchronize #2908
  • 10:03
    github-actions[bot] commented #2908
  • 10:01
    codecov[bot] commented #2908
  • 10:01
    codecov[bot] commented #2908
  • 10:00
    codecov[bot] commented #2908
  • 10:00
    codecov[bot] commented #2908
  • 10:00
    codecov[bot] commented #2908
  • 10:00
    codecov[bot] commented #2908
  • 10:00
    Suyoung789 synchronize #2908
  • 09:58
    codecov[bot] commented #2908
William Hayes
@wshayes
You have your application assets on Cloudfront? but not Traefik or FastAPI right?
Omri Har-Shemesh
@omrihar
Just as I posted this we managed to solve it - we didn't define cloudfront to forward query parameters!
So once we did this and waited the long time it takes to update it works.
Thanks!
euri10
@euri10
:bug: :)
William Hayes
@wshayes
Cool - thanks for sharing!
Omri Har-Shemesh
@omrihar
It was a sneaky one thou because we mostly had defaults that work and we didn't notice that the parameters don't change - until there was a default that didn't work in a specific setting
Francesco Bartoli
@francbartoli

You can add any fields you want to a JWT payload. I’ve seen tokens that have several dozen fields and are around 4kb in size - I think that’s a bit overdoing it :) It’s not a problem from the JWT spec/browsers/servers - just adds more IO to each request.

Thanks @wshayes, my first thought is to find a viable solution to receive authorization claims/roles from an external authentication system and spend it over a microservices architecture based on FastAPI

William Hayes
@wshayes
AWS Cognito, Auth0 and others allow you to add roles/claims and other user metadata as user attributes to the token. Note that the new Auth0 javascript library makes it much more difficult to get a JWT (instead they share a simple access token unless you slap it hard upside the head). I’ve not used Cognito yet, but I’ve been eyeing it as Auth0 seems to make hard things harder rather than slightly easier.
Neil Shapiro
@nrshapiro

@euri10, that's only the case in Docs as I mentioned. But others may show it in Google Chrome or elsewhere, where it looks like this:

image.png

euri10
@euri10
skaaptjop
@skaaptjop
@francbartoli another lighter weight solution is Google's firebase. Extremely straightforward to handle auth.
Francesco Bartoli
@francbartoli
Yep @skaaptjop, I played a bit with Firebase Auth but did not manag claims/roles at that time
skaaptjop
@skaaptjop
claims in FB are very lightweight (max 1000b I believe) so they do kinda expect any role based or other scheme to be implemented around it (with firestore for example)
David Montague
@dmontagu
@nrshapiro You can modify how the serialization happens by changing the response_class argument on your endpoint
the default response class (starlette.responses.JSONResponse) looks like this:
class JSONResponse(Response):
    media_type = "application/json"

    def render(self, content: typing.Any) -> bytes:
        return json.dumps(
            content,
            ensure_ascii=False,
            allow_nan=False,
            indent=None,
            separators=(",", ":"),
        ).encode("utf-8")
if you subclass and modify the render method to set indent=4 and separators=(", ", ": ") in json.dumps I think it will render closer to the "pretty" way
something like this:
import json
import typing

from starlette.responses import Response

class PrettyJSONResponse(Response):
    media_type = "application/json"

    def render(self, content: typing.Any) -> bytes:
        return json.dumps(
            content,
            ensure_ascii=False,
            allow_nan=False,
            indent=4,
            separators=(", ", ": "),
        ).encode("utf-8")
then using it would look like
    @app.get("/", response_class=PrettyJSONResponse)
    async def get_some_json():
        ...
David Montague
@dmontagu
This might be useful for debugging. If you wanted it on all endpoints during development (and off in production), this could be done by dynamically setting the response_class to a variable depending on the environment. But I think you'd be better served just making use of dev tools that will parse and display the json more neatly for you (e.g., the swagger docs, chrome extensions, etc.), and just occasionally making temporary use of the PrettyJSONResponse in situations where it is temporarily useful to have it pretty-printed
@nrshapiro As @wshayes said, there is a built-in way to skip default values as long as you don't explicitly set them to the default value when instantianting the model (pydantic must have skipped setting the values). So if the default value is None, and you don't pass it to the constructor, it will be skipped during serialization. (It was designed this way, rather than just skipping nulls, because otherwise, if you want it to include None for some reason, (e.g., because you updated a non-null value to become null, and want to signal that in your response), you wouldn't be able to.)
William Hayes
@wshayes
@dmontagu Thanks for that example - I added it to my gists for future reference!
euri10
@euri10
added flower and celery to my base, flower is super nicely made
William Hayes
@wshayes
do you use rabbitmq or redis with celery?
euri10
@euri10
I put rabbitmq but tbh I d'm not sure if I get the pros and cons of each one\
betaalpha
@betaalpha_gitlab
@wshayes I have just started using redis+celery
William Hayes
@wshayes
I’ve been using celery/rabbitmq - just finding rabbitmq more difficult to administer than I’d hoped. How is your experience with redis/celery?
I’m just now in the process of implementing a really simple queue/background process using Redis RPOPLPUSH directly to see it that will simplify my services/life/etc. Just finding Celery/… more complex than I need.
betaalpha
@betaalpha_gitlab
I have not yet experimented at a large scale. Presently it is in Proof-of-Concept stage.

var code="@app.get("/long_task", status_code=202) # 202=Accepted
async def long_task():
from backend.workers import tasks
mytask = tasks.long_task.apply_async(kwargs={'num':30})
return {'task_id': mytask.task_id}

@app.get("/long_task/status/{task_id}", status_code=200) # 200=OK
async def long_task_status(task_id: str):
from backend.workers import tasks
result = tasks.long_task.AsyncResult(task_id)
return {'status': result.status}
"

Sorry, new to giiter. How to send code part?
:)
euri10
@euri10
3 backticks
betaalpha
@betaalpha_gitlab

``` @app.get("/long_task", status_code=202) # 202=Accepted
async def long_task():
from backend.workers import tasks
mytask = tasks.long_task.apply_async(kwargs={'num':30})
return {'task_id': mytask.task_id}

@app.get("/long_task/status/{task_id}", status_code=200) # 200=OK
async def long_task_status(task_id: str):
from backend.workers import tasks
result = tasks.long_task.AsyncResult(task_id)
return {'status': result.status}
```

euri10
@euri10
code
betaalpha
@betaalpha_gitlab
code
euri10
@euri10
you can switch to compose mode icon on the right to do it easily
betaalpha
@betaalpha_gitlab
code
That black background thing is still not coming. I am in compose mode. Sending using Cntrl+Enter
William Hayes
@wshayes
Info on adding code samples and using compose mode
They don’t make it easy
You can also edit prior messages
betaalpha
@betaalpha_gitlab
I have to be in compose mode. Write the following: var code=<Copy/Paste my code>; and press Cntrl+Enter
Is it?

```var code="@app.get("/long_task", status_code=202) # 202=Accepted
async def long_task():
from backend.workers import tasks
mytask = tasks.long_task.apply_async(kwargs={'num':30})
return {'task_id': mytask.task_id}

@app.get("/long_task/status/{task_id}", status_code=200) # 200=OK
async def long_task_status(task_id: str):
from backend.workers import tasks
result = tasks.long_task.AsyncResult(task_id)
return {'status': result.status}";```

Damn. I am looking foolish...
euri10
@euri10
you miss return carriage after the backticks