@@ -1371,6 +1371,7 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
1371
1371
rd_kafka_topic_conf_t * tconf ;
1372
1372
Py_ssize_t pos = 0 ;
1373
1373
PyObject * ko , * vo ;
1374
+ PyObject * confdict = NULL ;
1374
1375
int32_t (* partitioner_cb ) (const rd_kafka_topic_t * ,
1375
1376
const void * , size_t , int32_t ,
1376
1377
void * , void * ) = partitioner_cb ;
@@ -1383,15 +1384,41 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
1383
1384
return NULL ;
1384
1385
}
1385
1386
1386
- if (!kwargs ) {
1387
- /* If no kwargs, fall back on single dict arg, if any. */
1388
- if (!args || !PyTuple_Check (args ) || PyTuple_Size (args ) < 1 ||
1389
- !PyDict_Check ((kwargs = PyTuple_GetItem (args , 0 )))) {
1390
- PyErr_SetString (PyExc_TypeError ,
1391
- "expected configuration dict" );
1392
- return NULL ;
1393
- }
1394
- }
1387
+ /* Supported parameter constellations:
1388
+ * - kwargs (conf={..}, logger=..)
1389
+ * - args and kwargs ({..}, logger=..)
1390
+ * - args ({..})
1391
+ * When both args and kwargs are present the kwargs take
1392
+ * precedence in case of duplicate keys.
1393
+ * All keys map to configuration properties.
1394
+ */
1395
+ if (args ) {
1396
+ if (!PyTuple_Check (args ) ||
1397
+ PyTuple_Size (args ) > 1 ) {
1398
+ PyErr_SetString (PyExc_TypeError ,
1399
+ "expected tuple containing single dict" );
1400
+ return NULL ;
1401
+ } else if (PyTuple_Size (args ) == 1 &&
1402
+ !PyDict_Check ((confdict = PyTuple_GetItem (args , 0 )))) {
1403
+ PyErr_SetString (PyExc_TypeError ,
1404
+ "expected configuration dict" );
1405
+ return NULL ;
1406
+ }
1407
+ }
1408
+
1409
+ if (!confdict ) {
1410
+ if (!kwargs ) {
1411
+ PyErr_SetString (PyExc_TypeError ,
1412
+ "expected configuration dict" );
1413
+ return NULL ;
1414
+ }
1415
+
1416
+ confdict = kwargs ;
1417
+
1418
+ } else if (kwargs ) {
1419
+ /* Update confdict with kwargs */
1420
+ PyDict_Update (confdict , kwargs );
1421
+ }
1395
1422
1396
1423
conf = rd_kafka_conf_new ();
1397
1424
tconf = rd_kafka_topic_conf_new ();
@@ -1403,8 +1430,8 @@ rd_kafka_conf_t *common_conf_setup (rd_kafka_type_t ktype,
1403
1430
/* Enable valid offsets in delivery reports */
1404
1431
rd_kafka_topic_conf_set (tconf , "produce.offset.report" , "true" , NULL , 0 );
1405
1432
1406
- /* Convert kwargs dict to config key-value pairs. */
1407
- while (PyDict_Next (kwargs , & pos , & ko , & vo )) {
1433
+ /* Convert config dict to config key-value pairs. */
1434
+ while (PyDict_Next (confdict , & pos , & ko , & vo )) {
1408
1435
PyObject * ks , * ks8 ;
1409
1436
PyObject * vs = NULL , * vs8 = NULL ;
1410
1437
const char * k ;
0 commit comments