Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 27 17:16
    j5awry closed #379
  • Jan 27 17:16
    j5awry commented #379
  • Jan 27 13:48
    jubrilissa synchronize #379
  • Jan 27 13:48
    jubrilissa synchronize #379
  • Jan 27 07:14
    nilendudas1422 labeled #407
  • Jan 27 07:14
    nilendudas1422 opened #407
  • Jan 25 19:47
    successor1 commented #145
  • Jan 25 16:17
    Smixi commented #404
  • Jan 17 17:48
    a-salimkhanov commented #243
  • Jan 17 05:30
    jingapore commented #403
  • Jan 15 19:44
    a-salimkhanov opened #406
  • Jan 11 16:11
    anandtripathi5 edited #405
  • Jan 11 16:09
    anandtripathi5 edited #405
  • Jan 11 16:09
    anandtripathi5 labeled #405
  • Jan 11 16:09
    anandtripathi5 opened #405
  • Jan 10 10:07
    heja1600 commented #27
  • Jan 10 10:05
    StephaneConq commented #27
  • Jan 10 10:05
    StephaneConq commented #27
  • Jan 10 10:05
    StephaneConq commented #27
  • Jan 09 23:02
    BullyBear commented #176
Abdur-Rahmaan Janhangeer
@Abdur-rahmaanJ
@j5awry After many failed attempts for basic auth, i think best is disable docs in production
John Chittum
@j5awry
@Abdur-rahmaanJ If you don't mind me asking, is this an on-prem or cloud hosted? And is it possible to add authentication at other layers? It depends a lot on your setup, but something like using JWT with NGinx, or x509 based auth at Apache Webserver are other possibilities. But there's a lot of nuance there. I do think we need to figure out a better way of handling the pre-generated doc endpoint, and I think what flasgger is doing could be an interesting entry point. but it's going to take code change in flask-restx
@E-Kalla : what version of flask-restx are you using again? And if you haven't, could you open an issue on our github? I think we're seeing various things that'd be nice to track in an issue.
E-Kalla
@E-Kalla

@E-Kalla : what version of flask-restx are you using again? And if you haven't, could you open an issue on our github? I think we're seeing various things that'd be nice to track in an issue.

I'm using flask-restx 0.3.0

E-Kalla
@E-Kalla
I opened an issue here python-restx/flask-restx#305 tell me if something is not clear , first time for me
Jason Weir
@Gidgidonihah
I just tracked down a bug in our own code related to flask_restx error handling when swapping from flask_restplus. The bug was that we were relying on the restplus bug that swallowed errors and we didn't know it. We had an error handler to handle custom error codes which should have dropped us into this block but instead we hit the else and threw a ValueError on line 705. Because flask_restplus swallowed errors, it worked, when swapping, it no longer did.
We tracked it down to the fact that the error handler was registered on the flask api, rather than the api instance. Fixed that and it worked as expected, but my questions is:
Should it have ignored error handlers on the app and only looked at api error handlers?
If the answer is yes, so be it, but I had to ask
John Chittum
@j5awry

@Gidgidonihah : Reading the code, the intent is that errorhandlers get checked for the restx.API and it's children (restx.API.namespace). It wouldn't make sense, to me, for the framework to go up the chain as well.

So self + children vs. self + parents + children. self + children makes sense to me for checking handlers. But I may be misinterpreting the question?

@E-Kalla : thank you. I think there's good information to start looking at things more closely. Sorry we can't react quickly. The community is small. Having it in an issue will help us keep track of comments and have higher visibility. I can also cross-check against current and past issues a bit easier.
Jason Weir
@Gidgidonihah
@j5awry I don't think you are misinterpreting. That was how I read the code as well. However, it did lead to an easy bug like this. Let me phrase the question like this. When would I want to register a handler on the flask app, and not have the framework use it? In this case, self is a child of the app, so it could also make sense that it bubbles up to that level, as it were.
1 reply
E-Kalla
@E-Kalla
Hello,
I have a question about marshal models.
How can I make a self reference in a model ?
https://prnt.sc/12kvzl2
I want my model 'error' can contain himself recursively.
But i'm struggling with ...
E-Kalla
@E-Kalla
actually , I want to this : https://marshmallow.readthedocs.io/en/stable/nesting.html#nesting-a-schema-within-itself
Is it possible without using marshmallow ?
Abdur-Rahmaan Janhangeer
@Abdur-rahmaanJ
@j5awry See https://aaronluna.dev/series/flask-api-tutorial/part-3/ "LINES 6, 14: The API will implement Bearer token authentication ..." and the comment below it

@Abdur-rahmaanJ If you don't mind me asking, is this an on-prem or cloud hosted? And is it possible to add authentication at other layers? It depends a lot on your setup, but something like using JWT with NGinx, or x509 based auth at Apache Webserver are other possibilities. But there's a lot of nuance there. I do think we need to figure out a better way of handling the pre-generated doc endpoint, and I think what flasgger is doing could be an interesting entry point. but it's going to take code change in flask-restx

Cloud-hosted, server-based auth is a great option also but see the above

1 reply
John Chittum
@j5awry
@E-Kalla : woof, self-reference. So, JSONSchema at a certain point started enabling more of that. I'd have to check on versioning. a lot of how the models are written and validated is based on JSONSchema v. 4. I'd have to look more closely at how to deal with something nested. But, unfortunately, restx models aren't as feature rich as Marshmallow
Henshal B
@henshalb
Hello, I have got a query.. How to add an additional GET into a class, may with a different name?
Henshal B
@henshalb
Just like an action decorator for django
John Chittum
@j5awry
hey all, we're cutting 0.4.0 release right now! flask and werkzeug both released 2.0.0. unfortunately, there are a few breaking changes we'll need to work through. You can pin flask and werkzeug yourself, but we're also pinning flask-restx for the moment till some upstream things fix, and we can make sure we've got any breaking changes accounted for
there are also some improvements and bugfixes. checkout the CHANGELOG.rst for quick hits
John Chittum
@j5awry
so i dropped by https://pypistats.org/packages/flask-restx thinking it'd show some interesting info -- our largest percentage of install is on 3.4 according to this
that's...worrisome since we've been talking about deprecating < 3.6. I'm wondering why there are so many 3.4 instals
alincmt
@ClimenteA
Hi, do you know how can I add @ns.doc (OpenApi) decorator with some default parameters in Namespace class?
I opened a question on stackoverflow (maybe others will need it): https://stackoverflow.com/questions/67530938/add-doc-decorators-on-namespace-instantiation-flask-restx
E-Kalla
@E-Kalla
Hello, I'm using marshmallow schema now , do you know the best way to documentate an API with marshmallow schema ?
I tried to keep @marshal_with(marshmallowschema)
But It didnt work, no error but swagger don't display anything.
I found https://apispec.readthedocs.io/en/latest/ is it the only solution ?
Thank you
John Chittum
@j5awry
honestly, if you're investing in marshmallow, apispec or moving to flask-smorest. smorest is the Marshmallow-Code version of flask-restx
E-Kalla
@E-Kalla
ok ;) and do you have some news about the deprecated Flask-RESTX request parse ? https://flask-restx.readthedocs.io/en/latest/parsing.html
John Chittum
@j5awry
nope. we keep saying "deprecated" because the original project had said so. But we haven't worked out anything different/better and regularly get people asking us to keep it
E-Kalla
@E-Kalla
ok thank you for reply !
Hamdi Burak Usul
@hbusul
Hello, we need a contributor to review pull request #341 . @j5awry was looking at the issue but we did not hear anything for a month. It would be really nice to use new werkzeug and flask with the flask-restx .
John Chittum
@j5awry
@hbusul sorry, it's been a very busy month. I've pulled in everything. I put up the changelog for the version. If anyone wants to give it a quick look before I merge and push the new version
Hamdi Burak Usul
@hbusul
@j5awry I can imagine, thanks for handling that :D . Our tests seems to do fine with the latest commit
E-Kalla
@E-Kalla
Hello ,
I have this issue for a while python-restx/flask-restx#314
I will try to take a look on the restx code but if you have an idea about where could this problem come from because it's really problematic.
If you have a polymorph field , you have to use marshmallow , then migrate all your api documentation on apispec, which is a very tedious work.
And even with apispec , swagger don't display the models correctly.
thank you
John Chittum
@j5awry
I've just run a release 0.5.0. it should end up in Pypi sometime~ish. I published the release on github, and bumped all the files appropriately
and the package.json should be a semver compliant thing now. i tried to hack on bumpr this morning, but since it appears to also be dead, i gave up
E-Kalla
@E-Kalla

Hey ,

I replied to the issue https://github.com/python-restx/flask-restx/issues/314#issuecomment-884753325
I think It can help a lot to resolve it

John Chittum
@j5awry

@E-Kalla thanks for really digging into the issue. I'd need to read a bit more to understand everything happening.

If you have an approach in mind, could you clearly state it in the issue? If it's to remove @cached_property i'm not sure the entire range of effects there, in particular with regards to benchmarking

serenanycvb
@serenanycvb:matrix.org
[m]

Hi, hope everyone is having a great Monday. I am currently setting up a POST method redirection using flask.redirect . For some reason, the redirection does not work and I was not able to get any useful logging even when I set FLASK_ENV=development. Here is the log I got:

127.0.0.1 - - [16/Aug/2021 16:49:57] "POST /runs HTTP/1.1" 200 -
[I 210816 16:49:57 _internal:122] 127.0.0.1 - - [16/Aug/2021 16:49:57] "POST /runs HTTP/1.1" 200 -

It seems this endpoint never got redirected.

Anyone has any insight on debugging this issue ?

Unfortunately, I am not able to provide any code here because the redirection works well when I tried to set up some dummy code, but it did not work with a big project that I am currently working on.

here is the log I got for dummy code that I set up:

127.0.0.1 - - [16/Aug/2021 17:04:51] "POST /todos2/1 HTTP/1.1" 307 -
127.0.0.1 - - [16/Aug/2021 17:04:51] "POST /todos/ HTTP/1.1" 200 -

From this log, the endpoint actually got redirected.

John Chittum
@j5awry
without code, it's hard to help debug.
serenanycvb
@serenanycvb:matrix.org
[m]
I am able to reproduce the error now, it was due to marshal_with which seems changed returned redirection:
Here is the code:
import flask
from flask import Flask
from flask_restx import Model, Resource, fields, Namespace, abort, Api
from werkzeug.middleware.proxy_fix import ProxyFix
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)
api = Api(app, version='1.0', title='TodoMVC API',
    description='A simple TodoMVC API',
)

ns = Namespace('todos', description='TODO operations')
ns2 = Namespace('todos2', description='TODO operations')

todo = Model('todo', {
    'id': fields.Integer(required=True, description='The task unique identifier'),
    'task': fields.String(required=True, description='The task details'),
    'description': fields.String(required=True, description='Put some description here')
})

response = Model('response', {
    'id': fields.Integer,
    'task': fields.String
})

ns.models[todo.name] = todo
ns.models[response.name] = response

todo2 = Model('todo2', {
    'task': fields.String(required=True, description='The task details'),
    'todo_description': fields.String(required=True, description='Put some description here')
})

response2 = Model('response2', {
    'id': fields.Integer,
    'task': fields.String
})

ns2.models[todo2.name] = todo2
ns2.models[response2.name] = response

api.add_namespace(ns)
api.add_namespace(ns2)

@ns2.route('/<int:id>')
@ns2.response(404, 'Todo not found')
class Todo(Resource):
    '''Show a single todo item and lets you delete them'''
    @ns2.doc('get_todo')
    def get(self, id):
        '''Fetch a given resource'''
        return "get todo 2"

    @ns2.expect(todo2)
    @ns2.marshal_with(response)
    def post(self, id):
        '''Update a task given its identifier'''
        if id == 1:
            redirection = flask.redirect(flask.url_for('todos_todo_list', _method='POST'), code=307)
            return redirection
        return {"id": "dummy id", "task": "some dummy task here"}


@ns.route('/')
class TodoList(Resource):
    '''Shows a list of all todos, and lets you POST to add new tasks'''
    @ns.doc('list_todos')
    def get(self):
        '''List all tasks'''
        return "get todo list"

    @ns.doc('create_todo')
    @ns2.expect(todo)
    @ns.marshal_with(response)
    def post(self):
        '''Create a new task'''
        payload = ns.payload
        return {"id": payload.get("id"), "task": payload.get("task")}


if __name__ == '__main__':
    app.run(debug=True)
John Chittum
@j5awry

so the requirement is:

Given an endpoint with a variable (var == $CONDITION), have a redirect only for $CONDITION, otherwise, return properly

My gut would say, if you want a single endpoint, split by condition, to do 2 redirects. One for $CONDITION, one for everything else. and the resultant endpoints handling the marshalling. Because, in the end, if their responses are going to be different, they should probably be considered separate endpoints

and that's going to be more properly rendered in the Swagger schema as well.
serenanycvb
@serenanycvb:matrix.org
[m]
Yes. The reason that I set up redirection is because, the endpoint already exists to do 2 things where separated by if-else condition statement.
For right now, I want to separate the 2 things into 2 different endpoints.
In order to not introduce breaking change for our users, so I decided to make the redirection from old endpoint to the new endpoint before fully separate them.
It would be nice to not remove marshaling because the old endpoint still needed to be kept.
John Chittum
@j5awry

Considering you're changing core functionality based upon a condition, i'd say keeping the original endpoint with 2 redirects, split by condition. then if you want to deprecate the v1 style endpoint later, you can

the other option is to split v1 and v2 endpoints, and just tell folks to use v2 for the new setup. Versioning and moving some endpoints is normal, and versioning is supported in flask-restx. you can provide version= to the API generator.

serenanycvb
@serenanycvb:matrix.org
[m]
Hi, John. Thank you for your suggestion. I think both are valid approaches. I think I am going to implement the first approach because we as a team had agree on not introducing breaking change for this new deployment and having this redirection will give users more time to adapt to the new endpoint.
E-Kalla
@E-Kalla
Hello ,
I have a question about marshalling.
I want to use marshall_with by passing a polymorph field map in argument , but it doesn't work , can someone help me ?
https://prnt.sc/1qfkppk
I want my function to be able to marshal list of this polymorph field
Carlos PiƱa
@cpinamtz_twitter

Hi, I have a question about how can I create a field which is a fixed list of different models:

model_1 = api.model(...)
model_2 = api.model(...)
model_3 = api.model(...)

model = api.model('model', {'field': fields.List([model_1, model_2, model_3])})

I know passing the list of previous models is not expected as the first param of the fields.List class but I don't know how to achieve it. Any ideas?

Matt
@mtcarr_gitlab
Hey folks, is there any way to define an arbitrary field in an api model?