Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Konrad Talik
    @ktalik
    Hi guys, I have a question. Shouldn't routes.generate_auto_route() provide dash "-" in regex? If no, how should I implement such functionality for uuid values within URLs? Wasn't sure if it is an issue but if yes, I can open it and create a pull request.
    Hamza Faran
    @hfaran
    Hey!
    Ah yes, making the regex configurable is something still to be done
    Feel free to open a PR fixing this if you want!
    Konrad Talik
    @ktalik
    kk, I see. thx for the answer!
    Hamza Faran
    @hfaran
    I guess the easiest way would be to make this an argument of the get_module_routes function
    And then have a sane kwarg default for it
    which IMO would be the exisitng one but with the hyphen added in
    Hamza Faran
    @hfaran
    Actually, I'm not too sure what the best solution for this is. It's kind of why this is still hardcoded because I wasn't sure how best to make it configurable.
    It could use tornado.options
    It could be a constant that you could monkeypatch
    or it could be passed all the way through from get_routes
    I'll see what your PR brings though :)
    Konrad Talik
    @ktalik
    I would say tornado.options < constant < kwarg value ;) or something like that
    But for start kwarg value will be fine
    Then you can expand it to take a default from constant or tornado.options
    Konrad Talik
    @ktalik
    Hi there. I have a question. I want to use schema validation but in the same time need to provide exceptions with {"status": "error", "code": error_code} instead of {"status": "success"}. How to do that without JSend wrapper OR how to validate JSend responses?
    Hamza Faran
    @hfaran
    I don't think I quite follow what you mean
    Could you give an example?
    Konrad Talik
    @ktalik

    Sure, here it is:

        @schema.validate(
            input_schema=INPUT_SCHEMA,
            output_schema=OUTPUT_SCHEMA,
            output_example=OUTPUT_EXAMPLE
        )
        def get(self):
            exception = EXCEPTION_XXX
            self.error(**exception)

    with constants:

    OUTPUT_SCHEMA = {
        "type" : "object",
        "properties" : {
            "elements" : {
                "type" : "array",
            }
        }
    }
    
    EXCEPTION_XXX = {
        "code" : 2,
        "message" : "Please provide more device properties.",
        "data" : {
            "elements" : [],
        }
    }

    When providing a valid JSON (like OUTPUT_EXAMPLE), there is no problem. But for self.error() server raises following exception (with a proper error response with no issue):

    TypeError: None is not of type 'object'
    
    Failed validating 'type' in schema['properties']['result']:
    (structure omitted)
    
    On instance['result']:
        None
    (structure has been omitted by me)
    Konrad Talik
    @ktalik
    There is no way to use schema validation with jsend methods. Do you think this is an issue or it's how it should be or am I doing something wrong?
    Hamza Faran
    @hfaran
    Hey
    Just got around to reading this
    Konrad Talik
    @ktalik
    Hi there
    Hamza Faran
    @hfaran
    So, from what I understand, you're trying to return a specific error from within a RequestHandler, correct?
    Konrad Talik
    @ktalik
    Yeah, from APIHandler. Forgot to mention that.
    Hamza Faran
    @hfaran
    Okay, you should be using APIError for this. This is how the API is designed for Tornado-JSON. The JSend methods aren't meant to be called directly! :)
    Somewhat relevant comment from an earlier issue: https://github.com/hfaran/Tornado-JSON/issues/76#issuecomment-118563408
    Konrad Talik
    @ktalik
    Wut, much thanks, I'll try with it! I'm somewhat new to Tornado :)
    Thx for the link
    Hamza Faran
    @hfaran
    Ah, well, APIError is a Tornado-JSON specific thing :P
    That is one of the example projects linked in the README
    If you ever want to raise an exception with error code and messages to propogate to the user, you should raise an APIError or use api_assert
    Konrad Talik
    @ktalik
    Brilliant
    Hamza Faran
    @hfaran
    No problem
    Konrad Talik
    @ktalik
    tornado_json.exceptions doc is missing. I think that confused me days ago ;) thanks for the examples
    Hamza Faran
    @hfaran
    Oh... so it is. How odd...