#490 closed defect (fixed)
[patch] incorrect handling of cursor.rowcount
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| Component: | Core (Management commands) | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
According to http://www.python.org/peps/pep-0249.html cursor.rowcount can be -1:
The attribute is -1 in case no executeXXX() has been performed on the cursor or the rowcount of the last operation is not determinable by the interface. [7]
E.g., SQLite3 returns -1 (hardcoded?).
This patch should fix it:
Index: management.py
===================================================================
--- management.py (revision 635)
+++ management.py (working copy)
@@ -218,7 +218,12 @@
# Check that the package exists in the database.
cursor.execute("SELECT 1 FROM packages WHERE label = %s", [app_label])
- if cursor.rowcount < 1:
+ if cursor.rowcount < 0:
+ # can be -1 (==undetermined) according to http://www.python.org/peps/pep-0249.html
+ flag = cursor.fetchone() is None
+ else:
+ flag = cursor.rowcount < 1
+ if flag:
# sys.stderr.write("The '%s' package isn't installed.\n" % app_label)
print _get_packages_insert(app_label)
@@ -232,11 +237,21 @@
contenttypes_seen[opts.module_name] = 1
for codename, name in perms:
cursor.execute("SELECT 1 FROM auth_permissions WHERE package = %s AND codename = %s", (app_label, codename))
- if cursor.rowcount < 1:
+ if cursor.rowcount < 0:
+ # can be -1 (==undetermined) according to http://www.python.org/peps/pep-0249.html
+ flag = cursor.fetchone() is None
+ else:
+ flag = cursor.rowcount < 1
+ if flag:
# sys.stderr.write("The '%s.%s' permission doesn't exist.\n" % (app_label, codename))
print _get_permission_insert(name, codename, opts)
cursor.execute("SELECT 1 FROM content_types WHERE package = %s AND python_module_name = %s", (app_label, opts.module_name))
- if cursor.rowcount < 1:
+ if cursor.rowcount < 0:
+ # can be -1 (==undetermined) according to http://www.python.org/peps/pep-0249.html
+ flag = cursor.fetchone() is None
+ else:
+ flag = cursor.rowcount < 1
+ if flag:
# sys.stderr.write("The '%s.%s' content type doesn't exist.\n" % (app_label, opts.module_name))
print _get_contenttype_insert(opts)
Attachments (1)
Change History (2)
by , 20 years ago
| Attachment: | management.patch added |
|---|
comment:1 by , 20 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
patch