diff options
| author | Olivier Dony <odo@openerp.com> | 2017-06-13 17:17:45 +0200 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2017-06-15 16:01:40 +0200 |
| commit | eb8d9190154a72d557674fcffb2a397bce5daed9 (patch) | |
| tree | 194fe3b183a26ef4517a913960ee88040ee8a160 | |
| parent | 46263eb398443f2e19c737c4488f43990f244085 (diff) | |
[FIX] sql_db: port fix from psycopg/psycopg2#459
NUL characters must not be used in query parameters,
as they will be ignored by libpq, being end-of-string
characters.
Preventing NULs avoids unexpected results from
queries. It is only necessary with psycopg2
versions before 2.7, which includes the upstream
fix.
| -rw-r--r-- | openerp/sql_db.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/openerp/sql_db.py b/openerp/sql_db.py index a3af4be677a..22bed4eabbc 100644 --- a/openerp/sql_db.py +++ b/openerp/sql_db.py @@ -63,6 +63,19 @@ psycopg2.extensions.register_type(psycopg2.extensions.new_type((700, 701, 1700,) import tools + +from tools import parse_version as pv +if pv(psycopg2.__version__) < pv('2.7'): + from psycopg2._psycopg import QuotedString + def adapt_string(adapted): + """Python implementation of psycopg/psycopg2#459 from v2.7""" + if '\x00' in adapted: + raise ValueError("A string literal cannot contain NUL (0x00) characters.") + return QuotedString(adapted) + + psycopg2.extensions.register_adapter(str, adapt_string) + psycopg2.extensions.register_adapter(unicode, adapt_string) + from tools.func import frame_codeinfo from datetime import datetime as mdt from datetime import timedelta |
