Skip to content

Commit

Permalink
Fix udf debugging and remove an annoying tox warning (#103)
Browse files Browse the repository at this point in the history
* Let exportparameters transfer the data as a hex string

In Python 3, pickles are bytes objects, not strings.
There seems to be a problem with py3embed and blobs,
so for the time being we use hex encoded strings.

* Fix tox DeprecationWarning about the imp module

Replace past.builtins.execfile with compile + exec
  • Loading branch information
joerivanruth authored Apr 5, 2022
1 parent 0158dae commit a2f7166
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
13 changes: 7 additions & 6 deletions pymonetdb/sql/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import tempfile
import re
import pdb
from past.builtins import execfile # type: ignore
from typing import Any, TYPE_CHECKING


Expand All @@ -27,7 +26,7 @@ def execute(self, query):
del dd['_conn']
del dd['_columns']
del dd['_column_types']
return pickle.dumps(dd);
return pickle.dumps(dd).hex();
};""")
self.__conn.execute("""
SELECT *
Expand Down Expand Up @@ -102,7 +101,8 @@ def debug(cursor, query, fname, sample=-1):
arglist, fcode.replace("\n", "\n "))
f.write(function_definition.encode('utf-8'))
f.flush()
execfile(f.name, globals(), locals())
compiled = compile(function_definition, f.name, 'exec')
exec(compiled, globals(), locals())

cleaned_arguments['_conn'] = LoopbackObject(cursor)
pdb.set_trace()
Expand Down Expand Up @@ -135,7 +135,7 @@ def exportparameters(cursor, ftype, fname, query, quantity_parameters, sample):
args, _, _, values = inspect.getargvalues(frame);
dd = {x: values[x] for x in args};
del dd['_conn']
return pickle.dumps(dd);
return pickle.dumps(dd).hex();
};""" % return_type
else:
export_function = """
Expand All @@ -162,7 +162,7 @@ def exportparameters(cursor, ftype, fname, query, quantity_parameters, sample):
dd[argname] = aux
print(dd[argname])
print(x)
return pickle.dumps(dd);
return pickle.dumps(dd).hex();
};
""" % (return_type, str(sample))

Expand All @@ -179,7 +179,8 @@ def exportparameters(cursor, ftype, fname, query, quantity_parameters, sample):
if len(input_data) <= 0:
raise Exception("Could not load input data!")

arguments = pickle.loads(input_data[0][0])
bin_data = bytes.fromhex(input_data[0][0])
arguments = pickle.loads(bin_data)

if len(arguments) != quantity_parameters + 2:
raise Exception("Incorrect amount of input arguments found!")
Expand Down
1 change: 0 additions & 1 deletion tests/test_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def tearDownClass(cls) -> None:
if cls.conn:
cls.conn.close()

@skip("Disabled, see issue #49")
def test_debug_udf(self):
self.cursor.execute("""
CREATE FUNCTION test_python_udf(i INTEGER)
Expand Down

0 comments on commit a2f7166

Please sign in to comment.