by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 20:56
    codecov[bot] commented #168
  • 20:56
    codecov[bot] commented #168
  • 20:55
    codecov[bot] commented #168
  • 20:55
    codecov[bot] commented #168
  • 20:55
    codecov[bot] commented #168
  • 20:54
    Rich107 edited #168
  • 20:54
    Rich107 edited #168
  • 10:38
    papasax commented #27
  • Jul 01 23:49
    vincent-heatseekr commented #167
  • Jul 01 23:48
    ykpark79 closed #167
  • Jul 01 23:48
    ykpark79 commented #167
  • Jul 01 17:49
    vincent-heatseekr commented #167
  • Jul 01 13:58
    dgrine commented #110
  • Jul 01 12:19
    ykpark79 labeled #167
  • Jul 01 12:19
    ykpark79 opened #167
  • Jun 30 13:59
    arajkumar review_request_removed #93
  • Jun 30 12:59
    Anogio edited #166
  • Jun 30 12:58
    Anogio edited #166
  • Jun 30 12:58
    Anogio labeled #166
  • Jun 30 12:58
    Anogio opened #166
John Chittum
@j5awry

@MeLight you can always install from source with pip. just enter the following in a requirements file

git+https://github.com/python-restx/flask-restx.git#egg=flask-restx

that will install master. To install specific revisions or branches, @$BRANCH before the #egg

git+https://github.com/python-restx/flask-restx.git@master#egg=flask-restx

Peter Slump
@Peter-Slump
Hi all, I think what @MeLight is trying to accomplish is a new release ;) Due to this bug (https://github.com/python-restx/flask-restx/issues/85) many users will not be able to use Flask-RestX currently however a fix is already in master. So could you do (at least) a patch release to fix this issue?
John Chittum
@j5awry

There is a ticket for tracking the release. Please understand we're an ad-hoc team with, i don't think, any official corp support, so it's all free time. and we're still sorting out release process after the forking. We had some broken automation, and wanted to pull in feedstock automation as well for folks using anaconda.

Also, as with a lot of folks, our little team is being hit by the COVID-19. Mostly folks having to do rushes, move to remote work, etc. We're working on fixing the automation and getting a release rolled as soon as we can.

Anthony Torres
@am17torres

Hi all. I'm having some issues configuring a polymorphic input payload on a post route. Does anyone have reference material on how to get this to work?

ns.expect(child1, child2, validate=True) is trying to validate the input payload against both children instead of either or.

ns=api.namespace('todo')
parent = api.model('Parent', {
    'name': fields.String,
    'type': fields.String(discriminator=True)
})

child1 = api.inherit('Child1', parent, {
    'extra': fields.String(required=True)
})

child2 = api.inherit('Child2', parent, {
    'extra2': fields.String(required=True)
})

@ns.route('/')
class TodoList(Resource):
    @ns.doc('create_todo')
    @ns.expect(child1, child2, validate=True)
    def post(self):
        return api.payload
Rikaelus
@Rikaelus

Hey guys, I'm transitioning from Flask Blueprints to RestX namespaces but I'm not sure how to convert a piece of functionality. I currently override Flask's Response.force_type method to append various things to all JSON responses, setting Flask to use my subclass with "app.response_class =".

How would I go about adding such logic to all responses in RestX? Marshalling seems to be in that direction but I feel I'd need to set a callback function to api.model or something to maintain my current level of response tweaking. The content that gets added to responses factors in user rights, user metadata, environment data, etc. So there's quite a bit of logic I run each time.

Thanks

Rikaelus
@Rikaelus
It's not a documented feature but this decorator seems to be effective so far: @api.representation('application/json')
John Chittum
@j5awry
@Rikaelus Hm...this is one i'll have to think about a bit. I've never used that flask functionality. not a workflow i'd really worked on
I did "or" by setting up jsonschema directly with subschema's of "anyOf" or "oneOf." did the same with marshmallow. but flask-restx is a little more stringent.
John Chittum
@j5awry
@am17torres it'd be great to capture your use cases in a ticket for expanding functionality. If you'd open a ticket and give as much info on what you'd like, please do. If you have already, I'll be doing some more grooming and commenting this week.
Rikaelus
@Rikaelus
@j5awry Seeing as I only needed to intercept application/json responses for modification , that decorator worked nicely to set my own version of the output_json function. The only other hitch was having to replace dumps with jsonify (to match what I had) but that was it.
I've already moved on to banging my head against Swagger doc decorators :)
John Chittum
@j5awry
Well, there's plenty of possible head banging there. You can make a representation of inputs/outputs separately and use api.doc for them. I've had to do that with some mutating things...
Rikaelus
@Rikaelus
Eh, it's mostly going to be a matter of silencing the perfectionist in me, when it comes to how things get displayed in swagger-ui
Mark Railton
@railto
Hi Folks, I'm wondering if it's possible to add a message to a response when using marshal_with. Current example is when updating a user, I want to return the updated user dict but also return a message saying the user was successfully updated. I'm not able to see anything in the docs about this so hoping somone here might have an idea
AJ Pryor, Ph.D.
@apryor6
Is there a way to pass a custom JSON encoder for generation of Swagger docs? I have an issue where default values that are provided via a function call in a Marshmallow schema cause JSON serialization errors in Swagger. apryor6/flask_accepts#69
Ben Steadman
@SteadBytes
@apryor6 It's not just for the Swagger docs but I think the RESTX_JSON Flask setting will work for this. I've added a comment to your issue https://github.com/apryor6/flask_accepts/issues/69#issuecomment-617316719 . Let me know if this helps :)
Ramiro Rivera
@ramarivera
Hi everyone!.
I am looking for some issues that would be good for some first contributions to this project, and was pointed to ask here
I have been using this library since it was flask-restplus and now I would really like to be able to contribute something back to it
Benjamin "Ziirish" SANS
@ziirish
Hi @ramarivera
thanks for the proposal
we definitely would love to have more contributions so we'll have a look and triage the issues
in the meantime, feel free to check the currently opend issues and if you feel like there is something you can do about any of them, please let us know
Rikaelus
@Rikaelus
Unfortunately the things I'd like the most are outside the capabilities of Swagger and, I think, even OpenAPI3's specs :(
jbhoorasingh
@jbhoorasingh
hello, can someone point me to the documentation if i want to have a field that list the parent of an object
Rikaelus
@Rikaelus
Hmm. I'm circling back to converting some of my more complex calls from Flask's app to RESTX and seem to have hit a very unexpected, very large wall. Can you not specify method-specific routes? I have a lot of functions that offer many routes for different filters, but I don't see how I can limit those routes to only GET, or leverage optionally used variables.
For instance, "/users" has alternate forms like "/users/3" (id=3 filter) or "/company/5/users" (company=5 filter) or "/users/username/testguy" (username=testguy filter)
And not all of those would be applicable to single-entity POSTs, PATCHes, DELETEs, etc.
David Cannings
@edeca_twitter
My app is deployed behind a proxy that terminates SSL and passes an HTTP request. The Swagger tries to load from http://x/api/swagger.json without SSL. What can I configure to ensure the base URL is always correct?
1 reply
John Chittum
@j5awry

@Rikaelus do you have other endpoints for /users/<variable> or just one in that exact path? does /users/username without a third path part return something, or should it return a 404?

You can do variables with <VARIABLE_NAME:TYPE> in the path. for what you've got above, if you do /users/<user_id:int> and someone passes /users/username with no continued pathing, it should be an err. I'd need to see what happens with /users/<var> and /users/usernames/<var> and see what happens.

3 replies
Guto Maia
@gutomaia

Hi guys, just switched from restplus to restx. I'm facing a particular problem when using Polymorfism:

parent_fields = {
    'index': fields.Integer(description='index')
}

parent = ns.model('Parent', parent_fields)

child1_fields = {
    'attr': fields.String(required=True, description='attr'),
}

child1 = parent.inherit('Child1', child1_fields)

child2_fields = {
    'attr': fields.String(required=True, description='attr'),
}

child2 = parent.inherit('Child2', child2_fields)


mapping = {
    child1: child1_fields,
    child2: child2_fields,
}


fields.List(fields.Polymorph(mapping))

That gives an TypeErro: unhashable type: 'Model'

1 reply
Am I doing it right?
Should I open a issue?
Guto Maia
@gutomaia
Well, I did some workarounds to avoid the unhashable error with a proper class with a dict interface:


parent_fields = {
    'index': fields.Integer(description='index')
}

parent = ns.model('Parent', parent_fields)

child1_fields = {
    'attr': fields.String(required=True, description='attr'),
}

child1 = parent.inherit('Child1', child1_fields)

child2_fields = {
    'attr': fields.String(required=True, description='attr'),
}

child2 = parent.inherit('Child2', child2_fields)


mapping = [
    (child1, child1_fields),
    (child2, child2_fields),
]

class Deck:

    def __init__(self, mapping):
        self.mapping = mapping

    def values(self, *args, **kwargs):
        return [k for k, v in self.mapping]

    def items(self, **kwargs):
        for k, v in self.mapping:
            yield k, v


fields.List(fields.Polymorph(Deck(mapping)))
Now I got an ValueError: Unknown class: Child1, going deeper on the restx code to fix it up, and make a PR. Any directions?
Blueswen
@Blueswen
Hi guys, I am trying to add some monitoring on my flask-restx app with prometheus, but got some questions. Is there a better package to add statsd middleware on flaks, or other recommended way to do monitoring? For now I am using gunicorn as wsgi server with statsd, but they didn't support custom metrics.
Shirish Kadam
@5hirish
Hi, I have a nested response structure and when I return response from the API the server shuts down with interrupted by signal 11: SIGSEGV signal. I tried using the Flask's @perform_after_request_tasks signal to see if this caused due to Flask or Flask-Restx but the response never reaches to this signal, leading me to believe that this must be due to Flask-Restx.
Following is a sample response structure:
 {
"data":
 [{
      "metric":"top_comment_hashtags",
      "insight":{
         "top":{
            "sapphic":2,
            "witchmemes":2,
            "greenwitch":1,
            "cottagecore":1,
            "grandmacore":1
         },
         "total":29,
         "unique":27
      },
      "since":"2020-05-14 08:47:58.386876",
      "mid":"2020-05-21 08:47:58.386885",
      "until":"2020-05-28 08:47:58.386887"
   },
   {
      "metric":"top_comment_mentions",
      "insight":{
         "top":{
            "charlieintheuniverse":18,
            "colourfulraine":15,
            "spiritwithinwillow":14,
            "emma":12,
            "xflabbergastedx":11
         },
         "total":271,
         "unique":59
      },
      "since":"2020-05-14 08:47:58.386876",
      "mid":"2020-05-21 08:47:58.386885",
      "until":"2020-05-28 08:47:58.386887"
   }
]}
Now if I try to respond only with one item in the list the server returns this response but If I add more than one to this response it ends-up throwing segmentation fault. This is left me pretty confused.
Shirish Kadam
@5hirish
If you copy-paste this structure, it will work as expected. But I suspect something is happening during the josnify phase in flask-restx?
Shirish Kadam
@5hirish
Ok I figured it out these int you see in the response are actually int64 a pandas type, which restx failed to serialize. Don't know why it was throwing SIGSEGV and quitting though
Benjamin "Ziirish" SANS
@ziirish
Nice catch @5hirish!
How did you manage to fix/workaround this issue then?
Bill Mittenzwey
@bmittenzwey
I'm using zappa to deploy my flask/flask-restx app to aws api gateway/lambda. All is good until i try to enable api keys. Since it applies to all routes, it renders the swagger ui pretty useless. Has anyone confronted this? Is there an obvious "right way" to do this that I'm not seeing?
Shirish Kadam
@5hirish
@ziirish I just had to caste it to int before sending it as response.
Anton
@Borschevik
I need to stream the data in my project into csv file. However, it seems for me that API is not working with Response in Flask. Is there a workaround or solution for this?
Leopold Pekaln
@leopold-p
Could someone please help me with my pull request? Literally 2 lines changed and suddenly codecov is red for no reason.
python-restx/flask-restx#165