Skip to content

Instantly share code, notes, and snippets.

@malthe
Created June 8, 2012 12:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malthe/2895420 to your computer and use it in GitHub Desktop.
Save malthe/2895420 to your computer and use it in GitHub Desktop.
Zope 2 patch to warn on transaction resource commits for a GET request
Index: src/Zope2/App/startup.py
===================================================================
--- src/Zope2/App/startup.py (revision 126687)
+++ src/Zope2/App/startup.py (working copy)
@@ -327,6 +327,9 @@
def abort(self):
transaction.abort()
+ def get(self):
+ return transaction.get()
+
def recordMetaData(self, object, request,
# Optimize global var lookups:
hasattr=hasattr, getattr=getattr,
@@ -362,7 +365,7 @@
# used to retrieve the object.
path = request_get('PATH_INFO')
- T = transaction.get()
+ T = self.get()
T.note(path)
auth_user=request_get('AUTHENTICATED_USER',None)
if auth_user is not None:
Index: src/ZPublisher/Publish.py
===================================================================
--- src/ZPublisher/Publish.py (revision 126687)
+++ src/ZPublisher/Publish.py (working copy)
@@ -13,7 +13,7 @@
"""Python Object Publisher -- Publish Python objects on web servers
"""
-import sys, os
+import sys, os, logging
import transaction
from zExceptions import Redirect
@@ -34,7 +34,9 @@
from .Request import Request
from .Response import Response
+LOG = logging.getLogger('ZPublisher')
+
class Retry(Exception):
"""Raise this to retry a request
"""
@@ -141,6 +143,14 @@
notify(PubBeforeCommit(request))
if transactions_manager:
+ if request.method == "GET":
+ tx = transactions_manager.get()
+ count = len(tx._resources)
+ if count:
+ LOG.warn((
+ "%d resources will commit on GET %s. " +
+ "This might be a bug!") % (
+ count, request['PATH_INFO']))
transactions_manager.commit()
endInteraction()
@myroslav
Copy link

myroslav commented Jun 8, 2012

It would be super useful to embed that information into transaction comment as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment