mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Ensure JSON data isn't modified in-flight by psycopg2 when using View/Edit data. Fixes #3600
This commit is contained in:
committed by
Dave Page
parent
a5d39003b6
commit
59446bb4b5
@@ -18,7 +18,6 @@ from flask import session
|
||||
from flask_babelex import gettext
|
||||
import psycopg2
|
||||
from psycopg2.extensions import adapt
|
||||
from psycopg2.extras import Json as psycopg2_json
|
||||
|
||||
import config
|
||||
from pgadmin.model import Server, User
|
||||
@@ -226,14 +225,7 @@ class Driver(BaseDriver):
|
||||
|
||||
@staticmethod
|
||||
def qtLiteral(value):
|
||||
adapted = None
|
||||
|
||||
# adapt function cannot adapt dict data type
|
||||
# Used http://initd.org/psycopg/docs/extras.html#json-adaptation
|
||||
if type(value) == dict:
|
||||
adapted = psycopg2_json(value)
|
||||
else:
|
||||
adapted = adapt(value)
|
||||
adapted = adapt(value)
|
||||
|
||||
# Not all adapted objects have encoding
|
||||
# e.g.
|
||||
|
@@ -17,6 +17,7 @@ import sys
|
||||
from psycopg2 import STRING as _STRING
|
||||
import psycopg2
|
||||
from psycopg2.extensions import encodings
|
||||
from psycopg2.extras import Json as psycopg2_json
|
||||
|
||||
from .encoding import configureDriverEncodings
|
||||
|
||||
@@ -166,6 +167,14 @@ def register_global_typecasters():
|
||||
# array of string type
|
||||
psycopg2.extensions.register_type(pg_array_types_to_array_of_string_type)
|
||||
|
||||
# Treat JSON data as text because converting it to dict alters the data
|
||||
# which should not happen as per postgres docs
|
||||
psycopg2.extras.register_default_json(loads=lambda x: x)
|
||||
|
||||
# pysycopg2 adapt does not support dict by default. Need to register
|
||||
# Used http://initd.org/psycopg/docs/extras.html#json-adaptation
|
||||
psycopg2.extensions.register_adapter(dict, psycopg2_json)
|
||||
|
||||
|
||||
def register_string_typecasters(connection):
|
||||
# raw_unicode_escape used for SQL ASCII will escape the
|
||||
|
Reference in New Issue
Block a user