#pocoo

/

      • troop_ has quit
      • nucleargrave has quit
      • nucleargrave joined the channel
      • nucleargrave
        ThiefMaster:
      • this is a tool for the government, getting approval for open source tools is a very lengthy process
      • ThiefMaster
        but all the stuff in anaconda is open source too ;x
      • nucleargrave
        second, installing dependencies when you don't need them just because you can do "pip install blah" is a terrible way to do everything
      • right but every single line needs to be approved by a lawyer and the licenses need to be valid
      • i submitted requests for a few libraries i'd like
      • but for now i'm limited to just the packages available with anaconda
      • ThiefMaster
        ugh, that sounds like a job i'm glad to not have ;)
      • nucleargrave
        so rather than arguing with me and telling me it's dumb, I'd rather get help and have my questions answered
      • not constructive whatsoever dude
      • ThiefMaster
        anyway, #python or a channel related to anaconda is probably the better place to ask., i doubt many people in here have even installed/used anaconda ;)
      • nucleargrave
        i'm using flask 11.0
      • ThiefMaster
        there is no flask 11.0, but i guess you mean 0.11 ;)
      • nucleargrave
        yeah 0.11
      • ThiefMaster
        anyway, object (de-)serialization is not flask-specific
      • nucleargrave
        i understand that, it's just somethign that at some point is part of any good web application so i am just asking for some patterns/advice on that
      • justanr
        nucleargrave: You can do something that I've never liked but could help you: include to_json and from_json methods.
      • nucleargrave
        yeah i have that but i'm talking for input validation purely
      • like i've been using json schema which is great
      • jsonschema*
      • ThiefMaster
        webargs is pretty nice.. but AFAIK that's marshmallow-based so probably not an option for you
      • justanr
        What sorts of validation are you looking for?
      • nucleargrave
        basically standard stuff, validate keys, types etc., jsonschema seems to do exactly what I need, but I'm not that experienced building API's and i saw that popular tools like Flask-Restful, RestPlus, and other extensions depend on marshmallow or marshmallow-esque libraries for serialization/deserialization
      • zoey joined the channel
      • like jsonschema will validate the request body
      • but then i'd like to also have validation in the business logic
      • justanr
        If jsonschema works, why find something else?
      • nucleargrave
        well that's my question really, what is the general usecase/benefit of using a library like schematics/marshmallow in this case?
      • i guess for me, i'd liek to have the framework completely isolated from the business logic
      • justanr
        A noble goal.
      • nucleargrave
        so jsonschema is pretty much tied to the framework right now
      • it have a decorator that validates the request arguments at the route level
      • justanr
        http validation is probably not part of your application, if you want to take a hard line stance on that.
      • nucleargrave
        but in my busienss logic, i have zero validation, and i'm looking for advice there
      • not sure what you man justanr
      • justanr
        I never use marshmallow to validate business logic.
      • nucleargrave
        gotcha
      • not really business logic, but say inputs that are going to be persisted in a database
      • justanr
        I use marshmallow as a boundary to pass HTTP serializable objects through.
      • nucleargrave
        popular tools i've encountered use marshmallow to validate objects prior to persisting them
      • justanr
        How are your objects getting into invalid states?
      • nucleargrave
        justanr: mind providing a high level example of what that means?
      • well they aren't at the moment thanks to jsonschema
      • justanr
        What I mean is the only point where I use marshmallow is between my application and HTTP (ergo Flask controllers/views)
      • nucleargrave
        but it just seems strange to not have any validation in the actual business logic code. I'm just validatidating the input at the framework level at the moment
      • justanr
        Or between requests and my application
      • nucleargrave
        so you take the request arguments from flask, transform them into marshmallow schema objects, and then transfer those to your data storage layer?
      • justanr
        Again: if jsonschema is working, why find something else?
      • My apps tend to be a little more involved than that, but yes.
      • nucleargrave
        well it works for me, but i'm also not super experienced, so i'm tryign to investigate other solutions before i impose this onto the team
      • justanr
        Well, not my primary app at work, that's a glorified UI for about twenty different systems, but it's also django and doesn't use a database. :p
      • nucleargrave
        flask extensions that i've seen all make heavy use of marshmallow/marshmallow-esque libraries to do what i'm doing, so i am just lookign for the best solution
      • justanr
        Assuming you get legal to sign off on marshmallow, I'd recommend that but I'm also bias having contributed to it and maintain an extension package for it as well.
      • nucleargrave
        i haven't seen any examples doing what I'm doing, so I think I am just using the tool incorrectly
      • which package?
      • i made the submission for marshmallow, so hopefully we get it
      • (that's very cool that you contributed to that btw)
      • justanr
        marshmallow_enum -- just ignore the release of shame I had to do because I bungled MANIFEST.in >_>
      • And also marshmallow-annotate, but that's mostly a joke package
      • nucleargrave
        sick
      • so ultimately i'd liek to get rid of my to_json/dict functions
      • and replace them with marshmallow
      • i suppose i can leave jsonschema as it does a different thing altogether
      • justanr
        Not having to dick with json methods is the biggest sell on Marshmallow to me.
      • d3prof3t joined the channel
      • nucleargrave
        so in your business layer, you don't actually work with the schema objects right?
      • justanr
        No, Python objects, or SQLAlchemy objects if I have to.
      • nucleargrave
        ok
      • justanr
        My flow is typically: HTTP -> Flask -> Marshmallow -> pass info to business layer -> return value -> Marshmallow -> Flask -> HTTP
      • *if* I need marshmallow
      • nucleargrave
        so an example usecase would then be: serialize request arguments to marshmallow object. Deserialize marshmallow object to native python object, then serialize to sql alchemy object?
      • justanr
        Depends on how architect wonk you want to go.
      • nucleargrave
        haha
      • justanr
        I can draw you up some great looking diagrams that are nice and decoupled but won't even begin to fit 90% of apps.
      • nucleargrave
        right now i just have jsonschema doing all of my input argument validation and I populate an error buffer and just return that of serialization fails
      • justanr
        If all you're doing is data in, data out jsonschema -> database is good enough
      • nucleargrave
        gotcha
      • so in my code, i just have hte assumption that data is valid upon getting to the controller/business logic code
      • which is why I was unsure about my approach
      • justanr
        If that's an assumption you can guarantee, then it works. That's what I do at work with my main app.
      • nucleargrave
        and the validation is on the framework side at the route level
      • gotcha
      • i maintain a route dictionary that basically has all the parameters to the add_url_rule function and as my view_func i pass a decorated pluggable view
      • wasn't sure if that was a pattern other people use, but I find it to be pretty flexible for the time being
      • and easy for other team members to debug
      • justanr
        The story is different on the other systems, but they're doing the heavy lifting in terms of logic and validation. We prefer to serialize anything but a GET to a command object that we can validate easily, and then objects determine if they can accept that command or not.
      • nucleargrave
        what do you mean by "a command object"?
      • kurashu89
        Just an object that represents a transition in state
      • nucleargrave
        i guess in my case, i let json schema do the work, and then just pass request.json() to my business logic code
      • kurashu89
        this is justanr, just in my mobile device because I haven't setup a bouncer
      • nucleargrave
        no problem, greatlya ppreciate the help once again
      • kurashu89
        Anyways, it all depends on your app and what it's solving. Doing something just because tutorials or blog posts show it isn't always right. That's how places end up with kubernetes when maestro-ng works just fine
      • nucleargrave
        yeah i mean i wouldn't just throw dependencies at somethign without understanding its benefit
      • what we have now works great, but it also could be a terrible solution which is why I come for advice
      • kurashu89
        Is it obvious what it's doing?
      • nucleargrave
        well it requires to just accept that jsonschema does magic
      • i have the schema files
      • and a validator decorator
      • dfee joined the channel
      • kurashu89
        It's not magic, 90% of serialization libs are looping and calling methods like validate, serialize and deserialize
      • nucleargrave
        i pass in the schema for validation at the route level
      • so when i'm registering all the routes at some piont, one of the view funcs looks ugly but it's a decorated pluggable view
      • that's the only non-obvoius part
      • because i have something hideous, but funtional like some_function(some_schema)(pluggable_view.as_vew())
      • justanr
        Add the decorator to the decorators attribute in the CBV.
      • nucleargrave
        the some_function returns a decorator
      • how do i pass an argument to it though?
      • i wanted to do that
      • justanr
        decorators = [serializer(schema)]
      • nucleargrave
        but there are multiple schemas for that one view right now
      • justanr
        the only gotcha is they're right to left in terms of application
      • nucleargrave
        (probably poor API design)
      • ah ok
      • justanr
        Depending on how you implemented the decorator, you might be able to apply straight to the method.
      • @serializer(schema) def get(self, ...)
      • nucleargrave
        i wasn't sure how to do it with pluggable views
      • if i could do that, that'd be ideal
      • i ddin't try
      • documentation said to populate the decorators attirbute
      • justanr
        Using decorators is probably the most preferred, but I've decorated methods as well.
      • nucleargrave
        decorated methods of pluggable views?
      • justanr
        Yeah
      • nucleargrave
        ah ok
      • i will 100% try that then
      • much cleaner
      • i thought i read somewhere that the methods wouldn't work with a decorator (i didn't question the logic at the time haha)
      • justanr
      • nucleargrave
        dude, thank you
      • that definitely will clean up some stuff for me
      • justanr
        Where the requires decorator looks like https://github.com/justanr/flask-allows/blob/62...
      • Note the inner inner function decoratored with wraps(f) accepts *args **kwargs and passes those on. With function views you'll only ever get kwargs, but with CBV ones you'll get a single positional argument that is the instance of the CBV
      • nucleargrave
        haha i came across that extension before, awesome that you wrote that
      • good to know
      • gtristan joined the channel
      • flaskbb is a cool project man, kudos. Definitely appreciate the help once again
      • audiofile joined the channel
      • another thing I have to worry about is a lack of flask-sqlalchemy. I'm currently using a modified version of the sql alchemy code provided in the flask documentation
      • TsunamiFoodTarge joined the channel
      • audiofile
        ah
      • That's there
      • That's what bugs me too
      • nucleargrave
        if the main benefits of flask-sql alchemy are pagination and the built in abort() stuff, then i don't need it
      • but what worries me is moreso the possibility of leaking database connections
      • so right now i am using a modified version of the sql alchemy snippet in the docs, and it's been workign well, but i haven't actually dug into the sql alchemy code or the flask sql alchemy extension to understand what it's doing yet
      • audiofile
        That sounds... dangerous
      • nucleargrave
        yeah definitely haha
      • unomystEz joined the channel