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

Set afterGet when the OPTIONS data is actually retrieved #827

Merged
merged 1 commit into from
Mar 29, 2017

Conversation

AparnaKarve
Copy link
Contributor

@AparnaKarve AparnaKarve commented Mar 28, 2017

API calls are async and therefore afterGet needs to be set once we have actually retrieved the data in getCredentialOptions from the API.options('/api/authentications') call.

Without this change, there is a chance that one could see an empty dropdown for a few brief seconds when the form is loaded as seen in the screenshot --
screen shot 2017-03-28 at 1 03 00 pm

@AparnaKarve
Copy link
Contributor Author

@miq-bot add_label fine/yes, bug

@AparnaKarve
Copy link
Contributor Author

/cc @mzazrivec @himdel @h-kataria Please review.

Noticed the issue in yesterday's heavy-duty testing.

@miq-bot
Copy link
Member

miq-bot commented Mar 28, 2017

Checked commit AparnaKarve@4f2ee61 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
0 files checked, 0 offenses detected
Everything looks good. 🏆

@mzazrivec mzazrivec self-assigned this Mar 29, 2017
@mzazrivec mzazrivec added this to the Sprint 58 Ending Apr 10, 2017 milestone Mar 29, 2017
@mzazrivec mzazrivec merged commit 0b36dcb into ManageIQ:master Mar 29, 2017
simaishi pushed a commit that referenced this pull request Mar 30, 2017
Set afterGet when the OPTIONS data is actually retrieved
(cherry picked from commit 0b36dcb)
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 6847a255821569beab1770f0a4cbb937d7c2d248
Author: Milan Zázrivec <[email protected]>
Date:   Wed Mar 29 10:41:03 2017 +0200

    Merge pull request #827 from AparnaKarve/ansible_empty_dropdown
    
    Set afterGet when the OPTIONS data is actually retrieved
    (cherry picked from commit 0b36dcb4380cd457ba5078b0366f8076ed671a10)

@himdel
Copy link
Contributor

himdel commented Mar 30, 2017

@AparnaKarve This breaks afterGet when the OPTIONS request responds faster than the API.get request for the edit code... seems like $q.all to wait on multiple promises may be your friend here :)

@AparnaKarve
Copy link
Contributor Author

@himdel #855 might be an answer to the edit case.

@himdel
Copy link
Contributor

himdel commented Mar 30, 2017

Not really, since that one deals with a different request entirely :) But thanks for that, that's exactly how I found this bug :).

But.. since more info is probably needed, the bug is this:

  1. we're editing something; afterGet == false
  2. API.options('/api/authentications') is called (and will eventually call getCredentialOptions)
  3. API.get('/api/authentications' + credentialId) is called (and will eventually call getCredentialFormData)
  4. if the options request has responded first, getCredentialsOptions will get called, causing afterGet = true, before getCredentialFormData was called, so we render the form without any data (except for the select options) => BUG

OTOH if the get request has responded first, getCredentialFormData is called, causing afterGet = true, causing the form to get rendered with all data except for the select options. Since you fixed exactly this for the new code path, I assume you'd consider this a bug as well.

The only way to make sure afterGet will be set to true only after both these requests have succeeded, you'd have to do essentially this...

    var select_promise = API.options('/api/authentications')
      .then(getCredentialOptions)
      .catch(miqService.handleFailure);

    var data_promise;
    if (credentialId !== 'new') {
      data_promise = API.get('/api/authentications/' + credentialId)
        .then(getCredentialFormData)
        .catch(miqService.handleFailure);
    } else {
       data_promise = Promise.resolve();
       // ...the rest of the else body...
    }

    $q.all([data_promise, select_promise])
      .then(function() {
        vm.afterGet = true;
      });

(and remove the other two afterGet = true)

@AparnaKarve
Copy link
Contributor Author

Ok, so either use $q.all or just good old chaining, i.e. handle the edit part of the code in getCredentialOptions.

What do you prefer?

@himdel
Copy link
Contributor

himdel commented Mar 30, 2017

Definitely $q.all since chaining means waiting for 2 request one after the other, while with $q.all, these requests can still happen in parallel.

Thanks for looking into this! :)

@AparnaKarve
Copy link
Contributor Author

Alrighty, you got it! :)

@AparnaKarve AparnaKarve deleted the ansible_empty_dropdown branch July 26, 2017 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants