Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pins)_: remove pins when the og message is deleted #6231

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

jrainville
Copy link
Member

@jrainville jrainville commented Dec 20, 2024

EDIT: I completely removed the migration in the end since we found that it actually breaks a behaviour of receiving a pin before a message. I also fixed the original issue without the migration but by manually deleting the pins when the message is deleted.

Turns out if you had old pinned messages that were still associated with deleted user messages, then the original migration didn't work. This fixes it.

If someone already ran the migration successfully because they didn't have deleted pinned messages, then it just won't run again and everything is already fine. If someone was blocked because of the migration, then it will just run fine now.

Thanks to @alexjba for find the cause

@status-im-auto
Copy link
Member

status-im-auto commented Dec 20, 2024

Jenkins Builds

Click to see older builds (16)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 754e2cd #1 2024-12-20 15:42:14 ~4 min windows 📦zip
✔️ 754e2cd #1 2024-12-20 15:42:36 ~4 min linux 📦zip
✔️ 754e2cd #1 2024-12-20 15:43:08 ~5 min android 📦aar
✔️ 754e2cd #1 2024-12-20 15:43:33 ~5 min ios 📦zip
✔️ 754e2cd #1 2024-12-20 15:44:23 ~6 min tests-rpc 📄log
✔️ 754e2cd #1 2024-12-20 15:44:47 ~6 min macos 📦zip
✔️ 754e2cd #1 2024-12-20 15:51:45 ~13 min macos 📦zip
✔️ 754e2cd #1 2024-12-20 16:08:30 ~30 min tests 📄log
✔️ 8c73295 #2 2025-01-07 15:21:28 ~4 min windows 📦zip
✔️ 8c73295 #2 2025-01-07 15:21:42 ~4 min macos 📦zip
✔️ 8c73295 #2 2025-01-07 15:21:53 ~4 min linux 📦zip
✔️ 8c73295 #2 2025-01-07 15:22:09 ~4 min ios 📦zip
✔️ 8c73295 #2 2025-01-07 15:24:13 ~6 min tests-rpc 📄log
✔️ 8c73295 #2 2025-01-07 15:24:20 ~7 min android 📦aar
✔️ 8c73295 #2 2025-01-07 15:25:49 ~8 min macos 📦zip
✔️ 8c73295 #2 2025-01-07 15:47:25 ~30 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 72a72bc #3 2025-01-10 16:31:19 ~3 min windows 📦zip
✖️ 72a72bc #3 2025-01-10 16:32:13 ~3 min tests 📄log
✔️ 72a72bc #3 2025-01-10 16:32:37 ~4 min macos 📦zip
✔️ 72a72bc #3 2025-01-10 16:32:52 ~4 min ios 📦zip
✔️ 72a72bc #3 2025-01-10 16:33:34 ~5 min linux 📦zip
✔️ 72a72bc #3 2025-01-10 16:33:49 ~5 min android 📦aar
✔️ 72a72bc #3 2025-01-10 16:34:22 ~6 min tests-rpc 📄log
✔️ 72a72bc #3 2025-01-10 16:37:32 ~9 min macos 📦zip
✔️ a0a0075 #4 2025-01-13 16:12:09 ~3 min windows 📦zip
✔️ a0a0075 #4 2025-01-13 16:13:18 ~4 min linux 📦zip
✔️ a0a0075 #4 2025-01-13 16:13:49 ~4 min ios 📦zip
✔️ a0a0075 #4 2025-01-13 16:14:36 ~5 min macos 📦zip
✔️ a0a0075 #4 2025-01-13 16:19:01 ~10 min android 📦aar
✔️ a0a0075 #4 2025-01-13 16:20:06 ~11 min macos 📦zip
✔️ a0a0075 #4 2025-01-13 16:23:08 ~14 min tests-rpc 📄log
✖️ a0a0075 #4 2025-01-13 16:49:17 ~40 min tests 📄log
✔️ a0a0075 #5 2025-01-14 15:00:21 ~29 min tests 📄log

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 56.25000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 61.67%. Comparing base (98e6483) to head (a0a0075).
Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
protocol/message_persistence.go 56.25% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6231      +/-   ##
===========================================
+ Coverage    61.54%   61.67%   +0.13%     
===========================================
  Files          842      842              
  Lines       110598   110612      +14     
===========================================
+ Hits         68067    68224     +157     
+ Misses       34582    34420     -162     
- Partials      7949     7968      +19     
Flag Coverage Δ
functional 21.55% <0.00%> (-0.01%) ⬇️
unit 60.20% <56.25%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
protocol/message_persistence.go 71.70% <56.25%> (-0.15%) ⬇️

... and 41 files with indirect coverage changes

@@ -1,3 +1,13 @@
-- Delete pinned messages that are not associated with any user message
-- This makes sure the migration below works even if a message is deleted
DELETE FROM pin_messages
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. So at the moment of running the migration, if we didn't yet receive the message, but we already received the pin_message, we will drop the information about the pinning action 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this also means that further, if we receive the pin_message before the message itself (which is possible), we won't be able to save it into the pin_message table, because message_id foreign key will not be found. Sounds not good, but maybe (hopefully) I'm missing smth?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's a great point, I didn't think about that! I guess we don't have a test covering that because it would have failed then.

I now realize that the original migration was already merged 😬

I wonder then if maybe I should revert it since there is that edge case you just found

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote a test real quick that receives a Pin before the actual message and it fails in the query with FOREIGN KEY constraint failed, because like you said @igor-sirotin , the message is not found.

I'm not sure what's the best course of action. I can revert the migration or we can try to find a way to still save the pin when the message doesn't exist yet? cc @osmaczko since he proposed the FOREIGN KEY migration. Before that, I just had a query that deleted the pins when we deleted the message #6173 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think of it either, sorry for that. Removing FOREIGN KEY constrain seems like a way to go.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igor-sirotin @osmaczko I removed the migration completely.

This means that people that had the issue with the previous migration will now be able to login correctly.

People that did run the migration previously will still be able to login as usual. However, they will have the edge case where if a pin message is received before the actual message, they will never see the pin, but that should be rare and more importantly, it will only be applied to dev accounts, never release accounts.

There is a way to fix it completely by applying the DELETE FROM pin_messages migration in this one and then creating a new migration that removes the CONSTRAINT.

What do you guys prefer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing migration completely sounds fine to me, as far as it affects only non-release users, as you mentioned.

Copy link
Collaborator

@igor-sirotin igor-sirotin Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrainville Yeah removing sounds good to me 👍
But why did we add FOREIGN KEY in the first place? To remove the rows in cascade? Then I guess we need a replacement for this behaviour?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why did we add FOREIGN KEY in the first place? To remove the rows in cascade? Then I guess we need a replacement for this behaviour?

Yes you are right. I will add a new issue after this one to do the behaviour manually without needing the constraint.
Similar to what I had here #6173 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue created here: #6246

@igor-sirotin @osmaczko can you give an approval to this one, I'll start working on the fix in a few.

@jrainville jrainville changed the title fix(migration)_: fix the pinned_messages migration when a message is deleted fix(pins)_: remove pins when the og message is deleted Jan 10, 2025
@jrainville
Copy link
Member Author

@igor-sirotin @osmaczko I actually put the fix in the PR directly and changed the title

@igor-sirotin
Copy link
Collaborator

We require commits to follow the Conventional Commits, but with _ for non-breaking changes. Please fix these commit messages:

chrore(migration)_: remove the migration totally since it is not right

@jrainville I thought something is wrong here and was looking in panic for a bug in parse_commits.sh.
Turned out you have a typo chrore 😄

Comment on lines 1793 to 1798
if err == nil {
err = tx.Commit()
return
}
// don't shadow original error
_ = tx.Rollback()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but would be nice to apply this pattern here: Skip deferred error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Let me know if I did it correctly

@jrainville
Copy link
Member Author

@osmaczko reminder to review please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants