Merge pull request #396 from CartoDB/pg12_compatibility

Make cartodb-postgresql python3 compatible (again)
This commit is contained in:
Manuel J. Morillo 2020-02-13 17:19:52 +01:00 committed by GitHub
commit 998402e531
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 5 deletions

View File

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

View File

@ -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)
* Reapply the changes in 0.33.0 (the issue we were looking for was unrelated)
* Reapply `Make PG12 depend on plpython3u instead of plpythonu`

View File

@ -197,8 +197,20 @@ CREATE OR REPLACE
FUNCTION @extschema@._CDB_Group_API_Auth(username text, password text)
RETURNS TEXT AS
$$
import sys
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;
-- 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[])
RETURNS int AS
$$
python_v2 = True
try:
import httplib as client
except:
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]
if params['host'] is None:
@ -222,7 +236,10 @@ $$
last_err = None
while retry > 0:
try:
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']
conn.request(method, url.format(database_name), body, headers)
response = conn.getresponse()