fix: create internal application when plugin adds Messenger after init#998
Open
TowyTowy wants to merge 1 commit into
Open
fix: create internal application when plugin adds Messenger after init#998TowyTowy wants to merge 1 commit into
TowyTowy wants to merge 1 commit into
Conversation
When a plugin gains the Messenger capability after it was first initialized for a user, its plugin conf already exists without an associated internal application (ApplicationID == 0). Messages sent by the plugin were then stored with application_id = 0, orphaning them: they disappeared on reload and could not be deleted (gotify#653). Back-fill the internal application during initialization when a Messenger plugin has none yet, mirroring the creation already done for plugins that support Messenger from the start. Fixes gotify#653 Co-Authored-By: Claude <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #998 +/- ##
==========================================
- Coverage 74.34% 74.25% -0.09%
==========================================
Files 66 66
Lines 3461 3473 +12
==========================================
+ Hits 2573 2579 +6
- Misses 688 691 +3
- Partials 200 203 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
eternal-flame-AD
left a comment
Member
There was a problem hiding this comment.
looks good to me, just one thing: can you add a double check in messagehandler.go to do a final check that the application ID is not zero? thanks. I wish we have foreign keys working.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #653
Problem
When a plugin implements the
plugin.Messengerinterface after it has already been initialized for a user, itsPluginConfalready exists with no associated internal application (ApplicationID == 0). On the next startup,initializeSingleUserPluginreuses that conf and wires the message handler withApplicationID: 0, so every message the plugin sends is stored withapplication_id = 0. Those messages are orphaned: they don't appear after a page refresh and can't be deleted (DELETE returns 404). This matches the maintainer's diagnosis in #653.Fix
On initialization, if a plugin supports
Messengerbut has no internal application yet (ApplicationID == 0), create one and persist it on the conf — mirroring what already happens for plugins that supportMessengerfrom the start. The internal-application creation is extracted into a shared helper. The back-fill is idempotent: plugins that already have an application are untouched.Testing
Added
TestNewManager_MessengerAddedAfterInit_createsApplication, which seeds a conf without an application and asserts an internal application is created after re-initialization with a Messenger-capable plugin. It fails onmaster(ApplicationID stays 0) and passes with this change.go test ./plugin/...,gofmt/gofumpt, andgo vetare clean.Disclosure: this change was prepared with assistance from Claude (an AI tool); all code was reviewed and verified by me.