Hi,

What I have seen happening that many people use __json__(self, request)
method on SQLAlchemy models. I find this dirty, as web subsystem should not
relevant to data persistency subsystem and there is a bleeding of
separation of concerns.

I'd rather have one adapter per model which gives serialize/deserialize
process which permission support so that the same serializer could support
e.g. anonymous and authenticated use cases.

In my ideal world

- All data would be described as Colander

- (semi-automatic) adapters would provide serializing between SQLAlchemy
model instances and Colander JSON schema

- Python docstrings could be used do describe objects in Colander schema

- Open API (swagger) schema could be generated from Colander schemas, thus
providing support for automatic Swagger client generation, API discovery
and such

Some more related work

https://github.com/stefanofontanelli/ColanderAlchemy

http://websauna.org/docs/narrative/form/autoform.html (wrapper of above)

https://pythonhosted.org/dictalchemy/

https://github.com/striglia/pyramid_swagger




On 7 June 2016 at 10:08, Iain Duncan <[email protected]> wrote:

> Hi folks, I'm working on an internal framework using Pyramid, Colander,
> and SQLAlchemy, and it's for much more enterprisey apps than I have
> previously done. We're looking at having a full fledged service layer, and
> using the ZCA as a DI framework a fair bit. I'm hoping folks can share
> their opinions on what they've found the best place and way to convert from
> validated dicts (originating from JSON from angular.js) to SA mapped
> objects is. I'm using Colander to validate the incoming json, which might
> be nested two or three levels deep, so after Colander conversion I know the
> fields in the dicts are ok, but they are still just python dicts.
>
> In the past, I used formencode to do both validation and conversion, but
> in this case I'm hoping to keep SQLA logic and coupling to a business/model
> layer that is more insulated from the web request layer so it can be used
> without issue from non-web-request contexts (rabbitqm jobs, scripts, etc).
> So I'm imagining right now that outside this business/model layer the web
> controllers are dealing with json and validating with colander, inside the
> business/model we are dealing with either proxy objects to the model
> objects or direct model objects, and somewhere (?) we convert.
>
> Any suggestions on what people have found to be good strategies or tools
> (or reading!) for localizing and controlling the conversion from dicts to
> mapped objects with relationships would be much appreciated. Or suggestions
> that I'm just wrong and why.
>
> thanks.
> (apologies for cross post if you already read this on the SQLAlchemy list!)
> Iain
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pylons-discuss/CAN9NcLzWeQRVEAZhU1OZMwrc0fDiahMxQw1W1f6QtjfJe4__LQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/pylons-discuss/CAN9NcLzWeQRVEAZhU1OZMwrc0fDiahMxQw1W1f6QtjfJe4__LQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Mikko Ohtamaa
http://opensourcehacker.com
http://twitter.com/moo9000

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/CAK8RCUv-p9jJhS%2BABxauZw3dc5QoY-voLfNVF7DYN6U1_BFodA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to