Skip to content

Commit c3a6064

Browse files
authored
Merge pull request confluentinc#175 from confluentinc/none_conf
None conf values are now converted to NULL (closes confluentinc#133)
2 parents 6cbbab9 + 505fdaf commit c3a6064

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

confluent_kafka/src/confluent_kafka.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,29 +1302,34 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
13021302
/*
13031303
* Pass configuration property through to librdkafka.
13041304
*/
1305-
if (!(vs = cfl_PyObject_Unistr(vo))) {
1306-
PyErr_SetString(PyExc_TypeError,
1307-
"expected configuration property "
1308-
"value as type unicode string");
1309-
rd_kafka_topic_conf_destroy(tconf);
1310-
rd_kafka_conf_destroy(conf);
1311-
Py_DECREF(ks);
1312-
return NULL;
1313-
}
1314-
v = cfl_PyUnistr_AsUTF8(vs);
1305+
if (vo == Py_None) {
1306+
v = NULL;
1307+
} else {
1308+
if (!(vs = cfl_PyObject_Unistr(vo))) {
1309+
PyErr_SetString(PyExc_TypeError,
1310+
"expected configuration "
1311+
"property value as type "
1312+
"unicode string");
1313+
rd_kafka_topic_conf_destroy(tconf);
1314+
rd_kafka_conf_destroy(conf);
1315+
Py_DECREF(ks);
1316+
return NULL;
1317+
}
1318+
v = cfl_PyUnistr_AsUTF8(vs);
1319+
}
13151320

13161321
if (rd_kafka_conf_set(conf, k, v, errstr, sizeof(errstr)) !=
13171322
RD_KAFKA_CONF_OK) {
13181323
cfl_PyErr_Format(RD_KAFKA_RESP_ERR__INVALID_ARG,
13191324
"%s", errstr);
13201325
rd_kafka_topic_conf_destroy(tconf);
13211326
rd_kafka_conf_destroy(conf);
1322-
Py_DECREF(vs);
1327+
Py_XDECREF(vs);
13231328
Py_DECREF(ks);
13241329
return NULL;
13251330
}
13261331

1327-
Py_DECREF(vs);
1332+
Py_XDECREF(vs);
13281333
Py_DECREF(ks);
13291334
}
13301335

tests/test_misc.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,32 @@ def stats_cb(stats_json_str):
6767
kc.poll(timeout=1)
6868
kc.close()
6969

70+
71+
72+
seen_stats_cb_check_no_brokers = False
73+
def test_conf_none():
74+
""" Issue #133
75+
Test that None can be passed for NULL by setting bootstrap.servers
76+
to None. If None would be converted to a string then a broker would
77+
show up in statistics. Verify that it doesnt. """
78+
79+
def stats_cb_check_no_brokers(stats_json_str):
80+
""" Make sure no brokers are reported in stats """
81+
global seen_stats_cb_check_no_brokers
82+
stats = json.loads(stats_json_str)
83+
assert len(stats['brokers']) == 0, "expected no brokers in stats: %s" % stats_json_str
84+
seen_stats_cb_check_no_brokers = True
85+
86+
87+
88+
conf = {'bootstrap.servers': 'something',
89+
'bootstrap.servers': None, # overwrites previous value
90+
'statistics.interval.ms': 10,
91+
'stats_cb': stats_cb_check_no_brokers}
92+
93+
p = confluent_kafka.Producer(conf)
94+
p.poll(timeout=1)
95+
96+
global seen_stats_cb_check_no_brokers
97+
assert seen_stats_cb_check_no_brokers
98+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy