The request factory doesn't fully do every step of initializing a request
since it's a user-overridable hook. It's not really intended to be used
directly. To have a fully initialize request you later need to do a couple
steps iirc.

1. request.registry = app.registry
2. pyramid.request.apply_request_extensions(request)

This is off the top of my head so I may be forgetting a step, apologies but
hopefully this is helpful.

The "right" way to do this is to use pyramid.scripting.prepare:

with pyramid.scripting.prepare(registry=app.registry) as env:
    request = env['request']

On Tue, Mar 25, 2025 at 12:27 PM Jonathan Vanasco <[email protected]>
wrote:

> I can't seem to generate a request properly.
>
> For example, in `main(`:
>
> from pyramid.interfaces import IRequestFactory
> from pyramid.request import Request
>
> app = config.make_wsgi_app()
> request_factory = app.registry.queryUtility(IRequestFactory,
> default=Request)
> request = request_factory.blank("/")
>
> The query for IRequestFactory always returns None,  leaving me with the
> default `Request` (which has none of the configured `add_request_method`
> attributes)
>
> I've also tried this using `get_app(config_uri)` from scripting.
>
> Am I querying the wrong interface, or is this just not a compatible
> use-case?
>
>
> --
> 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 view this discussion visit
> https://groups.google.com/d/msgid/pylons-discuss/c46029eb-e0c4-4f75-82d1-2971f55a49bcn%40googlegroups.com
> <https://groups.google.com/d/msgid/pylons-discuss/c46029eb-e0c4-4f75-82d1-2971f55a49bcn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 

Michael

-- 
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 view this discussion visit 
https://groups.google.com/d/msgid/pylons-discuss/CAKdhhwGmwe2SDV2asnwWiex9g79zBHsCjznmW-ixTESMvF7TEA%40mail.gmail.com.

Reply via email to