Opened 8 years ago
Closed 8 years ago
#28853 closed Cleanup/optimization (fixed)
Use database cursor as a context manager internally
| Reported by: | Jon Dufresne | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| 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
While reading the code Django code, I noticed some uses of connection.cursor() weren't being used as a context manager. For example:
def _reset_sequences(self, db_name):
...
cursor = conn.cursor()
for sql in sql_list:
cursor.execute(sql)
This pattern exists multiple time throughout Django. Using a context manager helps ensure resources are closed deterministically and that errors aren't hidden.
Change History (4)
comment:1 by , 8 years ago
| Has patch: | set |
|---|
comment:2 by , 8 years ago
| Component: | Uncategorized → Database layer (models, ORM) |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 8 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Note:
See TracTickets
for help on using tickets.
PR