Fix post_format not derived from post_topicPrefix#1631
Conversation
Test Results326 tests 325 ✅ 1m 41s ⏱️ Results for commit cbac86d. ♻️ This comment has been updated with latest results. |
|
The above patch fixes the settings so the publisher setting of "format" is set correctly. So far so good. I don't think the moth/ code takes the "format" into account to actually produce messages in the requested format. I looked at moth/init.py export any, and it expects a setting "post_format" to be there... where the setting is called "format" and this value is not being transferred from the publisher... so to actually get v02 messages... I think a bit more tweaking is needed. |
petersilva
left a comment
There was a problem hiding this comment.
I'm tempted to approve, but it is not doing the whole job... yes it fixes the post_format setting, gets it properly set in the publisher.
I don't think the value in the publisher is getting properly passed to postformat/init.py() ExportAny ... so probably need another patch to fix that... is it another branch or just more to this one?
|
Added |
|
So the last patch makes publishers explicitly use post_format. so I dunno... in general in moth when you have a post_ setting, the post_ gets removed in publishers and becomes the same setting without the post_ prefix... This is what is done for post_broker, post_exchange*, post_topicPrefix, etc... so... if we were consistent with other settings, the one used here would be format... but I don't know if this convention makes much sense or is worth following, so maybe just explicitly using post_format is fine. Opinions? |
|
@petersilva I think sticking with |
Code reviewFound 2 issues:
sarracenia/sarracenia/config/publisher.py Lines 84 to 86 in 390425b
sarracenia/sarracenia/config/publisher.py Lines 74 to 76 in 390425b Generated with Claude Code - If this code review was useful, please react with a thumbs up. Otherwise, react with a thumbs down. |
@andreleblanc11 which part is incorrect? |
|
Retracting the code review comment above -- both issues were wrong. I was looking at an intermediate commit ( Thanks guys. |
post_format defaulted to 'v03' in default_options, so hasattr(options, 'post_format') was always True in publisher.py. The elif branch that derives format from post_topicPrefix was never reached. A config with post_topicPrefix v02.post would silently post in v03 format. Change default to None so the topicPrefix derivation works. Explicit post_format still takes priority when set by the user.
Publisher now sets self['post_format'] alongside self['format'] so the options dict passed to PostFormat.exportAny/exportMine carries the correct post_format value.
Complete the post_ stripping pattern for format, matching how broker, exchange, and topicPrefix are already handled. Publisher.__init__ correctly sets self['format'] from post_format / post_topicPrefix, but Moth.__init__ and pubFactory were not copying it from the Publisher dict into self.o / props. This meant putNewMessage could fall back to body['_format'] instead of using the configured post_format. Add format promotion in both pubFactory (props['format']) and Moth.__init__ publisher_index block (self.o['format']), guarded by 'format' in publisher to stay consistent with the existing pattern for optional keys.
1. Restore 'or' guard on baseDir check (line 85). The 'and' operator does not short-circuit, so 'not self["baseDir"]' raises KeyError when the key is absent. The original 'or' correctly short-circuits. 2. Restore topicPrefix fallback to [] instead of None, matching Peter's deliberate fix in bab4b94. None causes TypeError when downstream code iterates or concatenates topicPrefix. Add adversarial tests for both bugs to prevent regression.
029bf1b to
c5d9da1
Compare
|
one last review @petersilva @andreleblanc11 @reidsunderland |


what
Setting
post_topicPrefix v02.postin a config should derivepost_format v02, but it doesn't. Peter found this while investigating the v02 regression (sr_insects#85) -- the format derivation has been broken since at least 3.00.56.root cause
In
config/__init__.py,post_formatdefaults to'v03'. Inpublisher.py, the logic is:Since
post_formatalways has a value, theelifbranch that derives format frompost_topicPrefixis dead code.the fix
post_formatdefault from'v03'toNoneNoneinpublisher.pyso the topicPrefix derivation kicks in when the user hasn't explicitly setpost_formatpost_formatstill takes priority when set by the userregression tests
New
tests/sarracenia/config/publisher_test.pywith 5 tests:test_format_defaults_to_v03-- neither post_format nor topicPrefix settest_format_derived_from_v02_topicprefix-- the bug casetest_format_derived_from_v03_topicprefix-- v03 topicPrefix still workstest_explicit_post_format_overrides_topicprefix-- user sets post_format, wins over topicPrefixtest_explicit_v02_post_format-- user sets post_format v02 directlycontext
Peter's investigation in sr_insects#85 and sarracenia#1623. The sr_insects sender config
tsource2send_f50.confhaspost_topic_prefix v02.postbut was silently posting v03 because format was never derived.