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

bug: Most videos are bookmarked, without explicitly being done. #635

Open
Zafeeruddin opened this issue May 14, 2024 · 9 comments
Open

bug: Most videos are bookmarked, without explicitly being done. #635

Zafeeruddin opened this issue May 14, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@Zafeeruddin
Copy link

Describe the bug
Videos till week-12 are bookmarked by default, and errors out if bookmark being removed
To Reproduce
Steps to reproduce the behavior:

  1. Uncheck bookmarks, which are previously bookmarked
  2. See error

Expected behavior
Expected:
a) No previous bookmarks, which I didn't do.
b) No error if uncheck it.
Screenshots or GIFs

image
Works fine for new bookmarks

@Zafeeruddin Zafeeruddin added the bug Something isn't working label May 14, 2024
@victorchrollo14
Copy link

This is a pretty weird bug. we can't reproduce it in development.
We could speculate why this error is happening.

  1. There is no Bookmark data in the database
    image

  2. but on the client side we are manual assigning some bookmark data like

{
    id: 5,
    userId: '1',
    contentId: 3,
    createdAt: new Date(),
}
  1. when you click on bookMark button, the deleteBookmarkHandler gets triggered and tries to run the following code to delete the bookmark data from db. since you don't have a bookmark record with id:5 and userId:'1' we are getting the prisma error.
  const userId = session.user.id;
  const { id } = data;
  console.log(id);
  try {
    const deletedBookmark = await db.bookmark.delete({
      where: { id, userId },
    });

@victorchrollo14
Copy link

The only way to reproduce this bug in dev would be to modify the addedBookmark state with wrong data that doesn't exist in database.

! Not sure why this bug would appear in production, we'll probably have to look through the data in prod. Right now in dev we are using less example data and in production we have more data so maybe the the current code which works for a single data item, might be producing this bug, when used with a lot of data.

export const useBookmark = (bookmark: Bookmark | null, contentId: number) => {
  const newBookmark = {
    id: 5,
    userId: '1',
    contentId: 3,
    createdAt: new Date(),
  };
  const [addedBookmark, setAddedBookmark] = useState<Bookmark | null>(
    newBookmark,
  );

Screenshot from 2024-05-15 11-17-34

@uttamsutariya
Copy link

Were you able to get the cause of this problem?
If you haven't started working on it, I can pick it up.

@victorchrollo14
Copy link

Were you able to get the cause of this problem?
If you haven't started working on it, I can pick it up.

I don't see this problem in development, it probably has something to do with the production database.

Go ahead and work on it, if you'd like to.

@uttamsutariya
Copy link

Picking up this issue

@uttamsutariya
Copy link

image

So the issue here is even my userId is 40541, the server action fetches the bookmark with any userId (exists in db) as you can see in below screenshots.

image
image
image
image

This is because there isn't any constraint while fetching all the contents.

image

There must be a constraint that makes sure we are fetching the bookmarks of the currently logged-in user only.

image

@victorchrollo14
Copy link

cool. nice job bro.
Did you insert more data into the database to test it out?

@Prakhar788
Copy link

@uttamsutariya how did you found out that issue is with bookmark:true by adding more videos or by creating a diff user?

@uttamsutariya
Copy link

Initially, I didn't do anything in my local cms.

I saw the prisma error message, then I tried to see the network request to remove the bookmark.

While doing this I saw that for each request the userId is not unique & not mine. So I felt that there is some issue with all the the fetched bookmarks.

Then I saw all the bookmarks have different different userId.

Now at that point I understood the problem that while fetching the content, the bookmarks are not being fetched of only mine, it's being fetched without any constraint of currently logged-in user.

So this way then I tried to create few users in my local db & resolved this issue.

So this kinda debugging skills you will eventually learn while working with prod databases & stuffs.

@hkirat Can you please review this PR as many people are struggling with the unexpected behaviour of bookmarks that they haven't added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants