Skip to content

Commit 88445af

Browse files
authored
[fix] TypeError: argument 2 must be str ... (#717)
- #716
1 parent 0a33d1d commit 88445af

File tree

7 files changed

+40
-10
lines changed

7 files changed

+40
-10
lines changed

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
Path(cwd, './common/src')]
4040

4141
setup(name='pinpointPy',
42-
version="1.3.2", # don't forget update __version__ in pinpointPy/__init__.py
42+
version="1.3.3", # don't forget update __version__ in pinpointPy/__init__.py
4343
author="cd_pinpoint members",
4444
author_email='[email protected]',
4545
license='Apache License 2.0',
@@ -61,6 +61,10 @@
6161

6262
"""
6363
# Changed
64+
## 1.3.3
65+
- fix `str(xxx)` #716
66+
## 1.3.2
67+
- update mysql-connector-python in #695
6468
## 1.3.1
6569
- fix bug https://github.com/pinpoint-apm/pinpoint-c-agent/issues/626
6670
## 1.3.0

setup_pypi_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
Path(cwd, './common/src')]
3838

3939
setup(name='pinpointPy',
40-
version="1.3.7", # don't forget update __version__ in pinpointPy/__init__.py
40+
version="1.3.8", # don't forget update __version__ in pinpointPy/__init__.py
4141
author="cd_pinpoint members",
4242
author_email='[email protected]',
4343
license='Apache License 2.0',

src/PY/_pinpoint_py.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,24 @@ static PyObject *py_pinpoint_add_clues(PyObject *self, PyObject *args) {
6363
*/
6464
static PyObject *py_pinpoint_add_clue(PyObject *self, PyObject *args) {
6565
char *key = NULL;
66-
char *value = NULL;
66+
// char *value = NULL;
67+
PyObject *value = NULL;
6768
int id = -1;
6869
int loc = 0;
69-
if (PyArg_ParseTuple(args, "ss|ii", &key, &value, &id, &loc)) {
70+
if (PyArg_ParseTuple(args, "sO|ii", &key, &value, &id, &loc)) {
7071
if (id == -1) {
7172
id = pinpoint_get_per_thread_id();
7273
}
73-
74-
pinpoint_add_clue(id, key, value, loc);
74+
PyObject *str_obj = PyObject_Str(value);
75+
if (str_obj) {
76+
// patch for https://github.com/pinpoint-apm/pinpoint-c-agent/issues/716
77+
// it likes str(value)
78+
const char *c_str = PyUnicode_AsUTF8(str_obj);
79+
if (c_str) {
80+
pinpoint_add_clue(id, key, c_str, loc);
81+
}
82+
Py_DECREF(str_obj);
83+
}
7584
}
7685
return Py_BuildValue("O", Py_True);
7786
}
@@ -265,7 +274,7 @@ static PyObject *py_pinpoint_enable_debug(PyObject *, PyObject *) {
265274
static PyObject *py_set_agent(PyObject *self, PyObject *args,
266275
PyObject *keywds) {
267276
// PyObject* setting;
268-
bool ret = false;
277+
// bool ret = false;
269278
char default_host[] = "collector_host";
270279
char default_tracelimit[] = "trace_limit";
271280
char default_timeout[] = "time_out_ms";

src/PY/test/testCoroutines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def pinpoint_trace(*args, **kwargs):
3030
self.assertEqual(value, '12345')
3131

3232
ret = await func(*args, **kwargs)
33-
_pinpointPy.add_clue('end', '3434', id)
33+
_pinpointPy.add_clue('end', b'3434', id)
3434
id = _pinpointPy.end_trace(id)
3535
return pinpoint_trace
3636

src/PY/test/testPinpoint.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def test_invalid_input(self):
2323

2424
def test_encode(self):
2525
_pinpointPy.start_trace()
26+
_pinpointPy.add_clue("key", bytes("value3", 'utf-8'))
2627
_pinpointPy.add_clues("CN", "测试中文编码")
2728
_pinpointPy.add_clues("KR", "한국어 인코딩 테스트 ")
2829
_pinpointPy.add_clues("JP", "日本語エンコーディングをテストする ")
@@ -39,6 +40,11 @@ def test_trace_life(self):
3940

4041
_pinpointPy.add_clue("key", "value")
4142
_pinpointPy.add_clue("key", "value3")
43+
_pinpointPy.add_clue('end', b'3434')
44+
_pinpointPy.add_clue('end', ('3434', '23'))
45+
_pinpointPy.add_clue('end', ['3434', '23'])
46+
_pinpointPy.add_clue('end', {'3434': 23, '23': 23})
47+
_pinpointPy.add_clue('end', 1314)
4248
_pinpointPy.set_context_key('sid', '12345')
4349
value = _pinpointPy.get_context_key('sid')
4450
self.assertEqual(value, '12345')

src/PY/test/testUnderProcessMode.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ def _test_api_flow(self):
2222
_pinpointPy.start_trace()
2323
_pinpointPy.set_context_key('sid', id)
2424
_pinpointPy.add_clue("key", "value3")
25+
_pinpointPy.add_clue("key", bytes("value3", 'utf-8'))
26+
_pinpointPy.add_clue('end', b'3434')
27+
_pinpointPy.add_clue('end', ('3434', '23'))
28+
_pinpointPy.add_clue('end', ['3434', '23'])
29+
_pinpointPy.add_clue('end', {'3434': 23, '23': 23})
30+
_pinpointPy.add_clue('end', 1314)
2531
_pinpointPy.add_clues("key", "value3")
2632
value = _pinpointPy.get_context_key('sid')
2733
self.assertEqual(value, id)
@@ -30,8 +36,8 @@ def _test_api_flow(self):
3036
_pinpointPy.force_flush_trace()
3137
_pinpointPy.drop_trace()
3238

33-
@unittest.skipIf(platform.system() == "Darwin", "skip Darwin")
34-
@unittest.skipIf(platform.system() == "Windows", "skip Windows")
39+
@ unittest.skipIf(platform.system() == "Darwin", "skip Darwin")
40+
@ unittest.skipIf(platform.system() == "Windows", "skip Windows")
3541
def test_process(self):
3642
p1 = Process(target=self._test_api_flow)
3743
p1.start()

src/PY/test/testUnderThreadMode.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ def _test_api_flow(self):
2323
self.assertTrue(_pinpointPy.trace_has_root())
2424
_pinpointPy.set_context_key('sid', '12345678')
2525
_pinpointPy.add_clue("key", "value3")
26+
_pinpointPy.add_clue('end', b'3434')
27+
_pinpointPy.add_clue('end', ('3434', '23'))
28+
_pinpointPy.add_clue('end', ['3434', '23'])
29+
_pinpointPy.add_clue('end', {'3434': 23, '23': 23})
30+
_pinpointPy.add_clue('end', 1314)
2631
_pinpointPy.add_clues("key", "value3")
2732
value = _pinpointPy.get_context_key('sid')
2833
self.assertEqual(value, '12345678')

0 commit comments

Comments
 (0)