Merge pull request #396 from CartoDB/pg12_compatibility

Make cartodb-postgresql python3 compatible (again)
feature/ch104711/create-cdb-map-config-table-with-triggers 0.36.0
Manuel J. Morillo 5 years ago committed by GitHub
commit 998402e531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,7 +1,7 @@
# cartodb/Makefile # cartodb/Makefile
EXTENSION = cartodb EXTENSION = cartodb
EXTVERSION = 0.35.0 EXTVERSION = 0.36.0
SED = sed SED = sed
AWK = awk AWK = awk
@ -108,6 +108,7 @@ UPGRADABLE = \
0.33.0 \ 0.33.0 \
0.34.0 \ 0.34.0 \
0.35.0 \ 0.35.0 \
0.36.0 \
$(EXTVERSION)dev \ $(EXTVERSION)dev \
$(EXTVERSION)next \ $(EXTVERSION)next \
$(END) $(END)

@ -1,3 +1,7 @@
0.36.0 (2020-02-13)
* Make `_CDB_Group_API_Auth` python3 compatible by passing bytes representation instead of a string.
* Make `_CDB_Group_API_Request` python3 compatible by adapting the function signature of `HTTPConnection`.
0.35.0 (2019-12-30) 0.35.0 (2019-12-30)
* Reapply the changes in 0.33.0 (the issue we were looking for was unrelated) * Reapply the changes in 0.33.0 (the issue we were looking for was unrelated)
* Reapply `Make PG12 depend on plpython3u instead of plpythonu` * Reapply `Make PG12 depend on plpython3u instead of plpythonu`

@ -197,8 +197,20 @@ CREATE OR REPLACE
FUNCTION @extschema@._CDB_Group_API_Auth(username text, password text) FUNCTION @extschema@._CDB_Group_API_Auth(username text, password text)
RETURNS TEXT AS RETURNS TEXT AS
$$ $$
import sys
import base64 import base64
return base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
data_to_encode = '%s:%s' % (username, password)
plpy.warning('DEBUG: _CDB_Group_API_Auth python v' + str(sys.version_info[0]))
if sys.version_info[0] < 3:
data_encoded = base64.encodestring(data_to_encode)
else:
plpy.warning('DEBUG: _CDB_Group_API_Auth entra')
data_encoded = base64.b64encode(data_to_encode.encode()).decode()
plpy.warning('DEBUG: _CDB_Group_API_Auth sale')
data_encoded = data_encoded.replace('\n', '')
return data_encoded
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE; $$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
-- url must contain a '%s' placeholder that will be replaced by current_database, for security reasons. -- url must contain a '%s' placeholder that will be replaced by current_database, for security reasons.
@ -206,10 +218,12 @@ CREATE OR REPLACE
FUNCTION @extschema@._CDB_Group_API_Request(method text, url text, body text, valid_return_codes int[]) FUNCTION @extschema@._CDB_Group_API_Request(method text, url text, body text, valid_return_codes int[])
RETURNS int AS RETURNS int AS
$$ $$
python_v2 = True
try: try:
import httplib as client import httplib as client
except: except:
from http import client from http import client
python_v2 = False
params = plpy.execute("select c.host, c.port, c.timeout, c.auth from @extschema@._CDB_Group_API_Conf() c;")[0] params = plpy.execute("select c.host, c.port, c.timeout, c.auth from @extschema@._CDB_Group_API_Conf() c;")[0]
if params['host'] is None: if params['host'] is None:
@ -222,7 +236,10 @@ $$
last_err = None last_err = None
while retry > 0: while retry > 0:
try: try:
conn = SD['groups_api_client'] = client.HTTPConnection(params['host'], params['port'], False, params['timeout']) if python_v2:
conn = SD['groups_api_client'] = client.HTTPConnection(params['host'], params['port'], False, params['timeout'])
else:
conn = SD['groups_api_client'] = client.HTTPConnection(params['host'], port=params['port'], timeout=params['timeout'])
database_name = plpy.execute("select current_database();")[0]['current_database'] database_name = plpy.execute("select current_database();")[0]['current_database']
conn.request(method, url.format(database_name), body, headers) conn.request(method, url.format(database_name), body, headers)
response = conn.getresponse() response = conn.getresponse()

Loading…
Cancel
Save