#18592 closed Cleanup/optimization (fixed)
Provide failure recovery for undocumented "_last_executed" in MySQLdb's cursor
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.4 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
A little bit of context: I'm trying to run django 1.4 on Google AppEngine using CloudSQL, vanilla django 1.4 (and pytz) are in my project directory.
So, in theory, I should be able to use django unmodified. Not the case I've found. I was getting a traceback when doing syncdb to "last_executed_query" in the mysql backend.
My workaround, or fix as it may be, is to change around line 238 in db/backends/mysql/base.py
from
def last_executed_query(self, cursor, sql, params): # With MySQLdb, cursor objects have an (undocumented) "_last_executed" # attribute where the exact query sent to the database is saved. # See MySQLdb/cursors.py in the source distribution. return cursor._last_executed
to
def last_executed_query(self, cursor, sql, params): # With MySQLdb, cursor objects have an (undocumented) "_last_executed" # attribute where the exact query sent to the database is saved. # See MySQLdb/cursors.py in the source distribution. return getattr(cursor, '_last_executed', None)
Attachments (1)
Change History (8)
by , 12 years ago
Attachment: | 18592.diff added |
---|
comment:1 by , 12 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 by , 11 years ago
Resolution: | fixed |
---|---|
Severity: | Normal → Release blocker |
Status: | closed → new |
The test introduced in this commit fails under Oracle -- probably because Oracle suffers from the same problem that was fixed for MySQL:
Also, I'm not convinced by this pattern:
try: do_stuff() except Exception: self.fail(...)
It does exactly the same thing as:
do_stuff()
but it obfuscate the error by swallowing the stack trace.
comment:5 by , 11 years ago
I'm sorry, but I have no Oracle setup (and don't intend to have one). If someone with Oracle knowledge could step in, would be nice!
About the pattern, I'm always a bit uncomfortable to create a test case without any assertion. And in that case, when the test fails, an error is raised. But it might be totally fine. Do you have a good reference about this? Then, if decided, we should fix all these patterns throughout Django tests.
comment:6 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed in c0a4894dca4bda0053a56cd677c80340a68c4c95
Thanks Shai!
Graceful failure for MySQL _last_executed