Quantcast
Channel: User Michael Merickel - Stack Overflow
Browsing latest articles
Browse All 41 View Live

Comment by Michael Merickel on Can I raise exception in python pyramid...

I totally agree with this by the way. The primary dbsession should be used for “successful” or “primary” work and if there’s other data you want to record outside of that then it should be done in a...

View Article


Comment by Michael Merickel on Gzipping all HTTP traffic with Pyramid

You can still install pip install paste fwiw.

View Article


Comment by Michael Merickel on How to protect a pyramid registry from changes...

a deep copy would be impossible - a shallow may be possible but I'm unaware of a public api for it

View Article

Comment by Michael Merickel on Using Pyramid events and multithreading

The issue here is that you cannot re-use the env as a context manager multiple times. I've provided the appropriate way in my answer.

View Article

Comment by Michael Merickel on few requests causes 503 errors (nginx,...

It's often done by nginx if the backend doesn't send any bytes in the response in a certain amount of time. Gunicorn may have similar settings.

View Article


Comment by Michael Merickel on Webob / Pyramid query string parameters out of...

Any chance you can reproduce it outside of your app?

View Article

Comment by Michael Merickel on Random NoTransaction in Pyramid

I suspect you only run into problems when running two requests at the same time which exposes some race conditions between the shared session being opened/closed in unexpected ways when each request is...

View Article

Comment by Michael Merickel on Connection pool to external services (redis)...

Globals are bad in almost every type of programming, albeit generally necessary in embedded domains. Globals are a type of side effect (state mutated/handled outside of the function signature) and make...

View Article


Comment by Michael Merickel on How can I compare a Javascript Variable with...

The answer is correct... jinja executes on the server and javascript executes in the client's browser. If you want to compare, then you have to get the jinja variable into javascript, and then it can...

View Article


Comment by Michael Merickel on How to prevent two users execute a function...

I think it's more complicated than a boolean field because you need a compare-and-set operation that is atomic. redis.io/topics/distlock has some information about using redis to do locking.

View Article

Comment by Michael Merickel on How do I manually commit a sqlalchemy database...

The code snippet I pasted, if put into a view callable, should work. If the celery task is invoked after the commit, as in the paste, and it's returning a NoResultFound, my suspicion is that there's...

View Article

Comment by Michael Merickel on How to reference artifact generated by...

Did you ever figure this out?

View Article

Answer by Michael Merickel for How to override python pyramid app config...

The configurator is where you should perform overrides. So the answer is to modify web_main or define your own. Pyramid has an override mechanism via config.include(), but it does not work one level...

View Article


Answer by Michael Merickel for When/where should openid tokens be validated...

Sure, you can store the JWT token in a cookie. You choose the authentication policy - just write one that does that instead of using one that stores it in the session.

View Article

Answer by Michael Merickel for Accessing Pyramid Settings throughout the program

Pyramid itself does not use global variables, which is what you are asking for when you ask for settings to be available in class-level or module-level attributes. For instance-level stuff, you can...

View Article


Answer by Michael Merickel for How to get a db session at Pyramid app...

If you're using the cookiecutter then it's pretty straightforward. The session factory is stored in config.registry['dbsession_factory'] and you can grab it and use it to make sessions whenever you...

View Article

Answer by Michael Merickel for Using Pyramid events and multithreading

get_current_registry() is trying to access the threadlocal variable Pyramid registers when processing requests or config to tell the thread what Pyramid app is currently active IN THAT THREAD. The...

View Article


Answer by Michael Merickel for Webob / Pyramid query string parameters out of...

As a simple example, this works fine for me, and the MultiDict has always preserved the order and so I suspect something is getting rewritten by something you're using in your stack.from pyramid.config...

View Article

Answer by Michael Merickel for Large scale pyramid application with multiple...

There's a lot to unpack in your question and it's probably too much for SO but I have a few comments.I would strongly urge avoiding a per-tenant schema where you're doing dynamic naming of tables. So...

View Article

Answer by Michael Merickel for Pyramid not included in Python virtualenv

You mentioned it's using buildout - I assume this is zc.buildout. buildout usually manages its own virtualenv and handles installing all of the necessary dependencies. It really depends on how that...

View Article

Answer by Michael Merickel for No transaction in add_finished_callback() -...

add_finished_callback runs after tweens and is generally where cleanup occurs, and is unordered, thus relying on a database connection to be open there is not a good idea.It's also worth nothing that...

View Article


Answer by Michael Merickel for Getting current route in pyramid view test

It's not super easy to mock current_route_path via DummyRequest because it relies on an IRoute object attached to it named matched_route as it's doing request.matched_route.name to get the route name...

View Article


Answer by Michael Merickel for How to use Pyramid to host static files at an...

filepath needs to be a url if you're expecting to put it as the src attribute in an img tag in your HTML. The browser needs to request the asset. You should be doing something like...

View Article

Answer by Michael Merickel for Python pyramid i18n and pytest

I suspect you aren't invoking config.begin() and config.end() correctly around your tests such that the threadlocals are active. It completely depends on how your tests look what this actually means...

View Article

Answer by Michael Merickel for Python pyramid encrypted session recommendation

I recommend https://docs.pylonsproject.org/projects/pyramid-nacl-session/en/latest/ which is an official addon for handling encrypted sessions. Beaker is also great and you can use that too.

View Article


Answer by Michael Merickel for How to port /{controller}/{action}/{id} routes...

Pyramid on its own requires granular route definitions. You can write helpers for this likedef add_action_routes(config, name, path=None): if path is None: path = name if not path.endswith('/'): path...

View Article

Answer by Michael Merickel for Deserialize Multidict using Colander

I suspect you'll want to use something like request.POST.mixed() which will return a list for the name key if multiple values were sent (but not a list if just one value) combined with maybe a colander...

View Article

Answer by Michael Merickel for pyramid security authenticating request

By default, authenticated_userid will not change in the same request in which you invoked remember. It is merely setting a cookie on the response object which the client will return on the NEXT request...

View Article

Answer by Michael Merickel for Trying to install Pyramid package with "python...

When you run python setup.py install directly, you are not using pip, so the version of pip you have installed is irrelevant. This command is antiquated, should not be used, etc, etc. The right answer...

View Article



Answer by Michael Merickel for Inconsistent ACL Permission on Pyramid/Websauna

I suspect websauna is not invoking your resolve_custom_principals function and is rather using its default resolve_principals function? I think it's pretty clear that the principals pulled in when...

View Article

Answer by Michael Merickel for Python Pyramid optional url segment

The view_defaults do not stack the way you probably think they do. You should only define view_defaults once for a class, and then it will add parameters to every view_config defined inside the class.

View Article

Answer by Michael Merickel for How do I do dependency injection in a python's...

To do this you'll need to define a custom view mapper which is the resource that is responsible for invoking a view. I'm unaware of any view mappers that come out of the box that will do this for you...

View Article

Answer by Michael Merickel for How can one combine pyramid_beaker...

At least one pattern is to decorate a closure that only accepts the args you want to cache and accesses other variables like request/dbsession from nonlocal scope.def view_func(request):...

View Article


Answer by Michael Merickel for How can I access a custom section in a Pyramid...

If you want to do that you'll have to parse the config file yourself. The section-isolation behavior you're seeing is intentional.def main(global_conf, **settings): parser = ConfigParser({'here':...

View Article

Answer by Michael Merickel for @reify executes database queries every time...

A signature like def user_details(self, user_id) has too many args to be supported by @reify or even @property. It should be def user_details(self). The reify decorator will then modify the attribute...

View Article

Answer by Michael Merickel for Pyramid fileresponse with header

The pattern in your example is valid, you should see the Content-Disposition header set on the response that way. As far as displaying it instead of downloading as an attachment I believe that the...

View Article


Answer by Michael Merickel for control order that routes are matched when...

The way the phases work in Pyramid doesn't allow you to re-order actions within a phase. Basically imagine that every call to config.add_route gets appended to a list, and then later that list is...

View Article


Comment by Michael Merickel on Is is possible to run a pyramid application...

Because you mention pserve I'll just throw out there that gist.github.com/mmerickel/ddcd86d3603979cac279d228e08716ce is basically a 95% replacement for all of pserve's functionality but works with any...

View Article

Answer by Michael Merickel for Editing Pyramid configuration .ini file at...

This is not the purpose of the configuration.ini file. It is explicitly intended to be readonly settings for your app. There is no thread-safety built into the settings dictionary. That being said,...

View Article
Browsing latest articles
Browse All 41 View Live


Latest Images