Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewEvent is not triggered by pyramid.scripting #520

Closed
dairiki opened this issue Mar 30, 2012 · 6 comments
Closed

NewEvent is not triggered by pyramid.scripting #520

dairiki opened this issue Mar 30, 2012 · 6 comments
Labels

Comments

@dairiki
Copy link
Contributor

dairiki commented Mar 30, 2012

I have a root_factory which depends on a custom request property (via config.set_request_property).

When the code in pyramid.scripting generates a request, it does not emit a NewRequest. This means that (when I try to run pshell, for example) my custom request property does not get set. Consequently, my root_factory pukes.

Is this all my fault, or is it a bug?

(If it is deemed a bug, I'd be happy to formulate a pull request. My hunch is that pyramid.scripting._make_request should emit a NewRequest event when it constructs a new request.)

Edited: I'm having trouble with pshell not pscript.

@mmerickel
Copy link
Member

This is a symptom of a larger issue with how bootstrap works. It currently just sets up the thread locals for you and doesn't really simulate a full request. Meaning that you can use the request to generate URLs and talk to your database but that's about it. What (might) be nice is to simulate a real request, but this isn't easy to do. The motivation here is that things like pyramid_tm aren't activated inside of a boostrapped environment so you have to do transaction.commit() yourself right now (and set your request properties). I'll wait for @mcdonc to chime in on this, however.

Is your root_factory puking before entering your script? A traceback would be nice regardless.

@dairiki
Copy link
Contributor Author

dairiki commented Mar 30, 2012

Oof. Nice to know that it's a "deep" problem, and not just me being stupid. Still, it seems to me that this particular part of problem is easily fixed. I'm a bit out of my depth though, so I could be wrong.

Sorry, it is pshell not pscript that is currently giving me trouble. A traceback is included below, but it's not that exciting. My root factory is trying to get a db session (normally available as a custom request property) so it can load the root. The custom property has not been set, which leads to an AttributeError. (I can work around this in my root factory without too much trouble.)

(py26-ale)dairiki@hairball$ pshell development.ini 
Traceback (most recent call last):
  File "/srv/w/users/dairiki/junk/python/virtualenvs/py26-ale/bin/pshell", line 9, in <module>
    load_entry_point('pyramid==1.3b3', 'console_scripts', 'pshell')()
  File "/srv/w/users/dairiki/junk/python/virtualenvs/py26-ale/lib/python2.6/site-packages/pyramid/scripts/pshell.py", line 14, in main
    return command.run()
  File "/srv/w/users/dairiki/junk/python/virtualenvs/py26-ale/lib/python2.6/site-packages/pyramid/scripts/pshell.py", line 90, in run
    env = self.bootstrap[0](config_uri)
  File "/srv/w/users/dairiki/junk/python/virtualenvs/py26-ale/lib/python2.6/site-packages/pyramid/paster.py", line 120, in bootstrap
    env = prepare(request)
  File "/srv/w/users/dairiki/junk/python/virtualenvs/py26-ale/lib/python2.6/site-packages/pyramid/scripting.py", line 80, in prepare
    root = root_factory(request)
  File "/srv/w/users/dairiki/git/discnw/python-rewrite/ale2/discnw/content/rootfactory.py", line 20, in root_factory
    session = request.dbsession
AttributeError: 'Request' object has no attribute 'dbsession'

@mmerickel
Copy link
Member

Thanks for the traceback, it confirms my suspicions that the error occurs not in your script but rather in the setup. Placing a NewRequest event in bootstrap makes me hesitant, but maybe the Pyramid logic for adding request properties can be modified to happen more automatically, without requiring the event be emitted.

@dairiki
Copy link
Contributor Author

dairiki commented Mar 31, 2012

maybe the Pyramid logic for adding request properties can be modified to happen more automatically, without requiring the event be emitted.

That is pretty straight-forward, I think. Here is a patch which does that:

dairiki/pyramid@52d7d51

Note that the above patch does not set the custom properties on any request instances explicitly passed in to prepare() or bootstrap(). That doesn't feel quite right to me, but it feels even more wrong to mess with any explicit request.

@mcdonc
Copy link
Member

mcdonc commented Mar 31, 2012

Looks good to me, how about you @mmerickel

mcdonc added a commit that referenced this issue Sep 11, 2012
…rty`` or

  ``config.add_request_method`` are now available to tweens.

- Request properties and methods added via ``config.set_request_property`` or
  ``config.add_request_method`` are now available in the request object
  returned from ``pyramid.paster.bootstrap``.

Related partially to issue #520 and issue #538 and issue #596, although it doesn't actually allow us to close any of them, because we still don't issue a newrequest event when bootstrap is used.
@mmerickel
Copy link
Member

This has been fixed in 7359873 and released in 1.4a1. The solution does not emit a NewRequest event, but it does attach request properties to the request.

spladug added a commit to reddit/baseplate.py that referenced this issue May 29, 2016
This adapter allows PasteDeploy-based tools to load a baseplate
application. In a baseplate-style config file, adding the line "use =
egg:baseplate" is all that's necessary.

Note: a root span is not automatically created in scripting context
(e.g. pshell) see Pylons/pyramid#520.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants