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

Initial values race condition #1292

Open
al-muammar opened this issue Apr 6, 2022 · 6 comments
Open

Initial values race condition #1292

al-muammar opened this issue Apr 6, 2022 · 6 comments

Comments

@al-muammar
Copy link

al-muammar commented Apr 6, 2022

Hi DAL team,

I have a problem that on opening a django admin page with DAL fields it doesn't have initial values, while making the same thing in Safari prepopulates all of the fields correctly. Also, when opening a new tab in Safari and pasting there the url, on the first load the initial values are empty, while after reloading they are prepopulated correctly.

My wild guess is that there is some race condition in JS code.

@al-muammar
Copy link
Author

al-muammar commented Apr 15, 2022

Okay, I was able to create a clear repro of the problem
https://user-images.githubusercontent.com/11528067/163552847-dd89b199-ff23-44bc-ac7e-4ea7282f6dec.mp4

Note that it only happens with the required fields. Optional fields doesn't get reset (see driver, it's also autocomplete).

@jpic , could you comment on it, please?

@al-muammar
Copy link
Author

Successful (initialized correctly) stack trace:

(anonymous) (jquery.js:6292)
domManip (jquery.js:6103)
after (jquery.js:6290)
jQuery.fn.<computed> (jquery.js:6398)
Select2._placeContainer (select2.full.js:5470)
Select2 (select2.full.js:5393)
(anonymous) (select2.full.js:6762)
each (jquery.js:381)
each (jquery.js:203)
$.fn.select2 (select2.full.js:6759)
(anonymous) (select2.js:92)
initialize (autocomplete_light.js:153)
each (jquery.js:381)
each (jquery.js:203)
(anonymous) (autocomplete_light.js:185)
mightThrow (jquery.js:3762)
process (jquery.js:3830)
setTimeout (async)
(anonymous) (jquery.js:3868)
fire (jquery.js:3496)
add (jquery.js:3555)
(anonymous) (jquery.js:3888)
Deferred (jquery.js:3979)
then (jquery.js:3873)
jQuery.fn.ready (jquery.js:4068)
(anonymous) (autocomplete_light.js:184)
(anonymous) (autocomplete_light.js:238)
load (async)
(anonymous) (autocomplete_light.js:30)

@al-muammar
Copy link
Author

al-muammar commented Apr 15, 2022

I set a breakpoint inside autocomplete_light.js:185 (initialize) and here is the difference. When everything initializes successfully, I see the following picture (for m2m field):
Screenshot 2022-04-15 at 11 22 19
While if the initialization is unsuccessful, the picture is as follows:
Screenshot 2022-04-15 at 11 22 03

I.e. there is a race condition on whether the child is selected or not. If it is selected before initialization happens, initialization is successful, while if it happens after, the field is reset.

@jpic
Copy link
Member

jpic commented Sep 9, 2022

Thanks for your report! Could you reproduce this with browsers other than safari?

@al-muammar
Copy link
Author

al-muammar commented Sep 11, 2022

@jpic, yes, this bug even more frequent in Chrome. I specifically made a video with Safari because it was easy to hit refresh a couple of times and get the correct behaviour.

@jpic
Copy link
Member

jpic commented Sep 15, 2022

Ok, thanks for your feedback!

I wonder if we still have the problem with this version: #1170

Easier is maybe to try with the serve.py script in the github.com/yourlabs/autocomplete-light repository

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

No branches or pull requests

2 participants