Re: Handling notices, warnings, etc.
James Henstridge <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
2009/5/28 Federico Di Gregorio <fog-NGVKUo/i/[email protected]>: > Il giorno gio, 28/05/2009 alle 13.15 +1000, Joel Nothman ha scritto: >> I am executing some PL/PGSQL scripts through a psycopg interface. >> >> During processing, my script outputs a number of notices. How can I have >> these notices printed when the procedure is executed through psycopg. >> (There seems to be some concept of notice processing in the source, but I >> haven't worked out how to access it through Python, and it doesn't seem to >> be documented.) > > You can access the .notices attribute of the connection object. It is a > list of notices received from the server. > >> Even better, how can I enable the handling of notices when accessing the >> connection through Django? > > I am sorry but I don't use django. You should be able to get to the notices with something like this: from django.db import connection # Create a cursor to ensure we are connected. cursor = connection.cursor() notices = connection.connection.notices Accessing the connection attribute on the DatabaseWrapper is probably not part of the public API, but probably won't break. So it is something to ensure you unit test in your app. James.