Here is the motivation for that:

https://github.com/Pylons/pyramid_tm/pull/55 
<https://github.com/Pylons/pyramid_tm/pull/55>

When Pyramid 1.9 drops, you’ll want to have the following:

rollbar -> pyramid_retry -> pyramid_tm -> EXC_VIEW -> your_app

Bert

> On Apr 28, 2017, at 12:25, Theron Luhn <[email protected]> wrote:
> 
> Thanks for pointing me to that SQLAlchemy cookie cutter, it was very helpful. 
>  I was able to get something up and working with pyramid_tm and 
> zope.sqlalchemy.
> 
> Do you know the motivation for pyramid_tm to be above EXC_VIEW by default?  I 
> moved it below EXC_VIEW since I wanted commit errors to be handled by the 
> exception views.  Is there any reason why I shouldn’t do this?
> 
> — Theron
> 
> 
> 
>> On Apr 28, 2017, at 12:12 AM, Bert JW Regeer <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>> Sorry, I fired a little too soon…
>> 
>> You might want to look at the current state of the art in our sqlalchemy 
>> cookie cutter:
>> 
>> https://github.com/Pylons/pyramid-cookiecutter-alchemy 
>> <https://github.com/Pylons/pyramid-cookiecutter-alchemy>
>> 
>> Request finalized callbacks are explicitly outside of tweens, and outside of 
>> any encapsulation.
>> 
>> You’ll want to look at pyramid_tm or build a tween yourself that handles 
>> things in a similar fashion.
>> 
>>> On Apr 28, 2017, at 00:20, Theron Luhn <[email protected] 
>>> <mailto:[email protected]>> wrote:
>>> 
>>> I have a pretty standard setup of Pyramid and SQLAlchemy, based off 
>>> http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/database/sqlalchemy.html
>>>  
>>> <http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/database/sqlalchemy.html>
>>> 
>>> However, this has a problem:  The `cleanup` callback executes *after* the 
>>> tween has returned.  I use tweens for both error logging (Rollbar) and 
>>> request logging (output via python-fluent-loggerd).  This means that if the 
>>> commit and associated flush fail, neither my request logger nor error 
>>> logging catch it.
>>> 
>>> For example, if my tween looked like this:
>>> 
>>> 
>>> class Tween:
>>>     def __init__(self, handler, register):
>>>         self.handler = handler
>>> 
>>>     def __call__(self, request):
>>>         start = time()
>>>         response = self.handler(request)
>>>         duration = time() - start
>>>         log(duration, response.status_code)  # This shows a success
>>>         return response  # session.commit() fails sometime after this
>>> 
>>> 
>>> The log call would report an HTTP 200, even the end result may be a HTTP 
>>> 500 due to a failure in session.commt()
>>> 
>>> The obvious solution is to move logging to the WSGI middleware layer, but 
>>> then I lose all the Pyramid-specific details, which I am loath to do.  I 
>>> could also manually add a try/except to handle errors in the cleanup and 
>>> report to Rollbar, but that still means my request logs show a success.
>>> 
>>> Is there a way I can force SQLAlchemy to commit/rollback (or at least 
>>> flush) before the passing the baton back to the tweens?
>>> 
>>> -- 
>>> 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] 
>>> <mailto:[email protected]>.
>>> To post to this group, send email to [email protected] 
>>> <mailto:[email protected]>.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/pylons-discuss/a98bf35f-d120-40b4-8168-fe4fc2f09f84%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/pylons-discuss/a98bf35f-d120-40b4-8168-fe4fc2f09f84%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>> For more options, visit https://groups.google.com/d/optout 
>>> <https://groups.google.com/d/optout>.
>> 
>> 
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "pylons-discuss" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/pylons-discuss/s5frQK7ES-s/unsubscribe 
>> <https://groups.google.com/d/topic/pylons-discuss/s5frQK7ES-s/unsubscribe>.
>> To unsubscribe from this group and all its topics, send an email to 
>> [email protected] 
>> <mailto:[email protected]>.
>> To post to this group, send email to [email protected] 
>> <mailto:[email protected]>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pylons-discuss/B511E99D-97ED-4088-AC83-230157C0E798%400x58.com
>>  
>> <https://groups.google.com/d/msgid/pylons-discuss/B511E99D-97ED-4088-AC83-230157C0E798%400x58.com?utm_medium=email&utm_source=footer>.
>> For more options, visit https://groups.google.com/d/optout 
>> <https://groups.google.com/d/optout>.
> 
> 
> -- 
> 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] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pylons-discuss/5CA12DCD-F1F8-40E1-9037-EDC270ED382E%40luhn.com
>  
> <https://groups.google.com/d/msgid/pylons-discuss/5CA12DCD-F1F8-40E1-9037-EDC270ED382E%40luhn.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/E189DD60-2F5A-4D44-96AF-FB5A5D43670D%400x58.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to