django-unfold icon indicating copy to clipboard operation
django-unfold copied to clipboard

Badge not changing between super user and staff user.

Open summerthe opened this issue 1 year ago • 6 comments

I created a repository and recorded a video to demonstrate that badge values are not changing between users. The values only update when the server restarts and then get cached for the user.

Steps to reproduce:

  • Create a superuser and a staff user.
  • Log in with both users in two different browsers or windows.
  • Initially, the values will be the same for both users, depending on whoever logged in first.
  • Restart the server and refresh the staff user's window first.

Here is repo link: https://github.com/summerthe/unfold-demo

simplescreenrecorder-2024-02-24_14 22 27

@lukasvinclav Let me know if you need anything else to reproduce this issue.

summerthe avatar Feb 24 '24 09:02 summerthe

@summerthe This is something what I already checked multiple times and it was always working for me BUT maybe I'm missing something. In our demo application at https://demo.unfoldadmin.com there is a badge in sidebar which is changing on each reload so the dynamic loading works at least in our demo.

Would you mind to check our demo repository https://github.com/unfoldadmin/formula and try to replicate the issue there? If there is a problem, I can take a look.

lukasvinclav avatar Mar 08 '24 10:03 lukasvinclav

@lukasvinclav I was able to replicate the same issue in the formula. I forked the formula and updated the badge callback to return a random integer or UUID based on the user type.

For staff user login, use the following username/password: demostaff/demostaff.

Check code here: https://github.com/summerthe/formula/commit/29532bca14f45838f81ab1a8373ec28902dea408

The callback's return value is changing, and it is possible that the request is being cached by whoever sends the first request after the server starts.

  • Log in with the superuser first and then with a staff member in another browser/incognito; you will see an integer for both users.
  • Restart the server.
  • Log in with a staff member first this time and then with the superuser in another browser/incognito; you will see a UUID for both users.

summerthe avatar Mar 09 '24 14:03 summerthe

@lukasvinclav same issue, looks like it depends on request, even if you trying to get some staff user related data it will display only data of first login user. Is it possible that request is being cached as @summerthe sad?

Also noticed that ENVIRONMENT callback works without this issue, here some examples: Using this callback with badge not showing actual id for some users:

def badge_callback(request):
    if request.user:
        return str(request.user.id)
    return ''

But using this callback with ENVIRONMENT works well:

def environment_callback(request):
    if request.user:
        return [str(request.user.id), 'warning' ]
    return ''

jSdmeman avatar Apr 02 '24 06:04 jSdmeman

@jSdmeman @summerthe thank you very much for the report. Now, I was able to replicate the issue locally. I created new PR #342 fixing the issue. Would you mind to test it locally if it works for you?

lukasvinclav avatar Apr 03 '24 17:04 lukasvinclav

@lukasvinclav just tested in local, it fixes the issue.

summerthe avatar Apr 04 '24 10:04 summerthe

@lukasvinclav thanks for so fast answer Tested your PR locally and on my project's dev server, looks like it works well. Thanks again!

jSdmeman avatar Apr 04 '24 18:04 jSdmeman