GitHub
04/23/2025, 9:16 AMSTATE from target clears Meltano state
Issue created by ReubenFrankel
### Singer SDK Version
0.44.3
### Is this a regression?
• Yes
### Python Version
3.9
### Bug scope
Targets (data type handling, batching, SQL object generation, etc.)
### Operating System
No response
### Description
Currently, an SDK target will always write a final STATE message after draining all sinks:
sdk/singer_sdk/target_base.py
Line 492 in</meltano/sdk/commit/dc7fd0d139dbdefbc291772d777d6d3e3c8b941b|dc7fd0d>
| self._write_state_message(state) |
| -------------------------------- |
If running with a (non-SDK1) tap that does not emit a STATE message (for example, when no new records are found), the final STATE message written by the target will contain an empty payload, as per
sdk/singer_sdk/target_base.py
Line 92 in</meltano/sdk/commit/dc7fd0d139dbdefbc291772d777d6d3e3c8b941b|dc7fd0d>
| self._latest_state: dict[str, dict] = {} |
| ---------------------------------------- |
sdk/singer_sdk/target_base.py
Line 482 in</meltano/sdk/commit/dc7fd0d139dbdefbc291772d777d6d3e3c8b941b|dc7fd0d>
| state = copy.deepcopy(self._latest_state) |
| ----------------------------------------- |
When receiving this STATE message from the target, Meltano will subsequently overwrite any existing state with the empty payload - effectively clearing state.
Is there a reason why an SDK target always emits a final STATE message? This could be handled by simply
if state:
self._write_state_message(state)
### Link to Slack/Linen
No response
## Footnotes
1. I'm pretty sure SDK taps always emit a final STATE message of their own, so this may only be an issue with certain non-SDK taps ↩️
meltano/sdkGitHub
05/13/2025, 5:47 PMSTATE from target clears Meltano state
Issue closed as completed by edgarrmondragon
meltano/sdk