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 ;-)
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/dbbf07fb50a100c9357eef4766... 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.l.ca...@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 ;-)
> --
> 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-discuss@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
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.
On Tuesday, July 17, 2012 2:02:38 AM UTC-4, Robert Forkel wrote:
> 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/dbbf07fb50a100c9357eef4766... > 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.l.ca...@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 ;-)
> > -- > > 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-discuss@googlegroups.com. > > To unsubscribe from this group, send email to > > pylons-discuss+unsubscribe@googlegroups.com. > > For more options, visit this group at > > http://groups.google.com/group/pylons-discuss?hl=en.
On Tuesday, July 17, 2012 9:07:03 AM UTC-4, andre.l.caron wrote:
> 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é
> On Tuesday, July 17, 2012 2:02:38 AM UTC-4, Robert Forkel wrote:
>> 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/dbbf07fb50a100c9357eef4766... >> 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.l.ca...@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 ;-)
>> > -- >> > 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-discuss@googlegroups.com. >> > To unsubscribe from this group, send email to >> > pylons-discuss+unsubscribe@googlegroups.com. >> > For more options, visit this group at >> > http://groups.google.com/group/pylons-discuss?hl=en.
For posterity, the Pyramid project does not intend on fixing this limitation<https://github.com/Pylons/pyramid/pull/638#issuecomment-7050642>. 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).