Duplicate OnChanMsg calls in python modules #865

Closed
opened 2026-10-05 04:49:13 +02:00 by adam · 6 comments
Owner

The title says it all. I have observed that the OnChanMsg method on a python module is being called twice per message. It seems that modpython calls OnChanMsg in its override of OnChanTextMessage https://github.com/znc/znc/blob/d58563a88014610b0fd1112e74f7e127d55774b4/modules/modpython/znc.py#L640 but so does the core https://github.com/znc/znc/blob/d58563a88014610b0fd1112e74f7e127d55774b4/src/Modules.cpp#L947

The title says it all. I have observed that the `OnChanMsg` method on a python module is being called twice per message. It seems that `modpython` calls `OnChanMsg` in its override of `OnChanTextMessage` https://github.com/znc/znc/blob/d58563a88014610b0fd1112e74f7e127d55774b4/modules/modpython/znc.py#L640 but so does the core https://github.com/znc/znc/blob/d58563a88014610b0fd1112e74f7e127d55774b4/src/Modules.cpp#L947 <!-- github-sync-id:345483227 -->
adam closed this issue 2026-10-05 04:49:13 +02:00
Author
Owner

Your python module is broken, and doesn't follow the contract. My telepathy skills tell me that you didn't return the EModRet value from your OnChanMsg, but next time please pastebin the module, so that I don't have to guess.

Your python module is broken, and doesn't follow the contract. My telepathy skills tell me that you didn't return the `EModRet` value from your `OnChanMsg`, but next time please pastebin the module, so that I don't have to guess. <!-- github-comment-id:408644065 -->
Author
Owner

The module in question is https://github.com/snoonetIRC/znc-modules/blob/master/push.py and you were correct. The original author of the module neglected to return znc.CONTINUE from some of the callbacks that have an EModRet return value. Sorry to bother you.

The module in question is https://github.com/snoonetIRC/znc-modules/blob/master/push.py and you were correct. The original author of the module neglected to return `znc.CONTINUE` from some of the callbacks that have an `EModRet` return value. Sorry to bother you. <!-- github-comment-id:408645626 -->
Author
Owner

Your python module is broken, and doesn't follow the contract. My telepathy skills tell me that you didn't return the EModRet value from your OnChanMsg, but next time please pastebin the module, so that I don't have to guess.

According to the modpython documentation, functions that return None should have a 'reasonable default' substituted (If a callback returns None, a reasonable default is substituted. If a callback raises an exception, the default value is assumed too. Note: You should return something explicitly anyway (PEP 20), also such default behavior WILL be changed in some future version.)

The function being called twice does not exactly fit under reasonable default, and while this is now a deprecated function, it should still maintain past functionality. Or the docs should be changed to indicate that a return is required rather than simply suggested. Especially given that this was not always the case.

>Your python module is broken, and doesn't follow the contract. My telepathy skills tell me that you didn't return the EModRet value from your OnChanMsg, but next time please pastebin the module, so that I don't have to guess. According to the [modpython documentation](https://wiki.znc.in/Modpython), functions that return None should have a 'reasonable default' substituted (`If a callback returns None, a reasonable default is substituted. If a callback raises an exception, the default value is assumed too. Note: You should return something explicitly anyway (PEP 20), also such default behavior WILL be changed in some future version.`) The function being called twice does not exactly fit under `reasonable default`, and while this is now a deprecated function, it should still maintain past functionality. Or the docs should be changed to indicate that a return is **required** rather than simply suggested. Especially given that this was not always the case. <!-- github-comment-id:408994055 -->
Author
Owner

also such default behavior WILL be changed in some future version

It was changed in 1.7, alright :) But docs should be updated to reflect this, sure.

> also such default behavior WILL be changed in some future version It was changed in 1.7, alright :) But docs should be updated to reflect this, sure. <!-- github-comment-id:409055011 -->
Author
Owner

This started as an implementation detail, followed by the description of current behavior, with no guarantees that this behavior will persist, even vice versa, it was suggested that it will not persist.

This started as an implementation detail, followed by the description of current behavior, *with no guarantees* that this behavior will persist, even vice versa, it was suggested that it will *not* persist. <!-- github-comment-id:409055619 -->
Author
Owner

Agreed, on both counts

Agreed, on both counts <!-- github-comment-id:409255355 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/znc#865