Opened 10 years ago

Last modified 10 years ago

#25020 new New feature

Provide/log related args (SQL query, params, proc) with database errors

Reported by: Daniel Hahler Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no
Pull Requests:How to create a pull request

Description

Database errors should provide the SQL query being used (the sql and maybe params separately), e.g. in case of a DataError.

DatabaseErrorWrapper might just log these as an error, in case the reason is for the exception message not getting too long - but it's probably easier/better to apply this to CursorWrapper.execute, CursorWrapper.executemany and CursorWrapper.callproc (via some specialized context manager, which could be passed in relevant args that should be logged or added to the exception in case of error)?

It is annoying to figure out where e.g. some varchar length restriction might come from, and the SQL/params would make it more obvious.

While you can log queries with the django.db logger, CursorDebugWrapper or directly in Postgres, the former (logging queries in general) is noisy (and therefore not useful / usually enabled by default) and logging them in your DB should be abstracted away by Django and might be even not possible, in case you cannot control the DB settings in this regard.

According to the ticket's flags, the next step(s) to move this issue forward are:

  • To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is: [https://github.com/django/django/pull/#### PR].

Change History (1)

comment:1 by Tim Graham, 10 years ago

Triage Stage: UnreviewedAccepted

There's probably room for improvement here.

Note: See TracTickets for help on using tickets.
Back to Top