Re: Writing a decorator that returns a Pyramid view.

210 views
Skip to first unread message

Robert Forkel

unread,
Jul 17, 2012, 2:02:38 AM7/17/12
to pylons-...@googlegroups.com
Hi André,
i guess this is with venusian >= 1.0a6. I ran into a similar problem
with cornice, and managed to find a workaround:
https://github.com/xrotwang/cornice/commit/dbbf07fb50a100c9357eef47668528cb83096c9b
Note the depth argument passed explicitely to venusian.attach which
controls down to which depth venusian will go down the import stack
(although i didn't fully understand this feature and the need for it
myself).
This may be not possible in your case, though, if you are not calling
venusian.attach in your own code but rely on view_config.
regards
robert

On Mon, Jul 16, 2012 at 3:30 PM, andre.l.caron <andre....@gmail.com> wrote:
> Hi All!
>
> I've encountered what I believe to be a bug in Pyramid and I hope you can
> help me find a solution or workaround :-)
>
> I have some rather redundant code in Pyramid views and I'm trying to
> refactor it into a decorator. The idea is that this decorator will return a
> Pyramid view function decorated with @view_config and the redundant code
> will be put into this "generated" function so that it automagically applies
> in all view functions. This works fine, but as soon as I move my decorator
> to a seperate module and import it (it needs to be used from multiple
> modules that define views) then I get HTTP 404 errors.
>
> I've taken a look at the Pyramid and Venusian source code, but I'm not
> familiar with some of the more advanced stuff going on in Venusian to
> properly determine exactly why this doesn't work.
>
> I've attached an SSCCE[1] (~100 lines of code,with comments) that
> demonstrates this problem. Can you please take a look at it and confirm
> that this is a bug (or not)?
>
> Note: I've tried to keep this as close to possible to how it's used in the
> real application. Keep in mind that this is legacy code and I'm not behind
> all the decisions (e.g. the do-it-yourself-RPC framework ;-)
>
> Thanks,
> André Caron
>
> [1]: http://sscce.org/
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/V39AjAbHCmgJ.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discus...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.

andre.l.caron

unread,
Jul 17, 2012, 9:07:03 AM7/17/12
to pylons-...@googlegroups.com
Hi Robert,

Thanks for the info, I applied a custom patch to "pyramid.view.view_config()" to add a "depth=N" argument and setting "view_config(..., depth=2)" inside the imported decorator fixes everything.  I'll see if I can submit a patch to the Pyramid project.

Thanks!
André
> To post to this group, send email to pylons-discuss@googlegroups.com.
> To unsubscribe from this group, send email to

andre.l.caron

unread,
Jul 17, 2012, 4:56:32 PM7/17/12
to pylons-...@googlegroups.com
I submitted a [bug and a patch][1] on the Pyramid project.

andre.l.caron

unread,
Jul 18, 2012, 8:07:46 AM7/18/12
to pylons-...@googlegroups.com
For posterity, the Pyramid project does not intend on fixing this limitation.  If you encounter this problem, you will have to bypass the use of `@view_config` and use `Configurator.add_view()` manually (or through some other custom registration scheme).
Reply all
Reply to author
Forward
0 new messages