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 UpdateModuleSetting in ModuleController #3360

Merged

Conversation

engineering87
Copy link
Contributor

Fix the 'UpdateModuleSetting' method in ModuleController refactoring the update module conditions.
Issue #2868

Summary

Modified the update conditions, removed the 'settingExist' variable and check directly the settings value.

@bdukes bdukes changed the base branch from development to release/9.4.x December 2, 2019 22:32
Copy link
Contributor

@bdukes bdukes left a comment

Choose a reason for hiding this comment

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

This change seems fine, but I don't see how it would fix #2868. That issue is that updating an existing settings doesn't have an effect, but this code does the exact same existValue != settingValue check in that scenario, right? I'm probably missing a piece to understanding this change. Do you have a sample module you've been testing with which demonstrates the fix works?

@engineering87
Copy link
Contributor Author

Hi Brian,
I tested the change with a simple test module defined in this way:

protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                const string key = "TestProperty";
                ModuleController.Instance.UpdateModuleSetting(ModuleContext.ModuleId, key, "False");
                var moduleInfo = ModuleController.Instance.GetModule(ModuleContext.ModuleId, ModuleContext.TabId, true);
                var value = moduleInfo.ModuleSettings[key];
                if (value != null && value.ToString() == "False")
                {
                    ModuleController.Instance.UpdateModuleSetting(ModuleContext.ModuleId, key, "True");
                    moduleInfo = ModuleController.Instance.GetModule(ModuleContext.ModuleId, ModuleContext.TabId, true);
                    value = moduleInfo.ModuleSettings[key];
                    if (value == null || value.ToString() == "False")
                    {
                        throw new ModuleLoadException("Second update failed");
                    }
                }
                else
                {
                    throw new ModuleLoadException("First insert/update failed");
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

the TestProperty is correctly set in the ModuleSettings table.

Actually I haven't tried the same code with the unpatched version yet but reading the issue it seems that the problem is consistent. Regarding the original code, the second condition in 'else if' was executed only when the 'settingValue' was null.

@bdukes
Copy link
Contributor

bdukes commented Dec 3, 2019

I tried your test code and it appears to work correctly on 9.4.3 (without this patch). @mitchelsellers were you testing a different scenario in #2868?

@mitchelsellers
Copy link
Contributor

@bdukes This appears to have fixed itself from when I initially posted it as well, as I just validated that I have modules working with 9.4.1 and 9.4.2 that do not experience the issue in #2868

@valadas valadas changed the base branch from release/9.4.x to develop December 3, 2019 23:51
@bdukes
Copy link
Contributor

bdukes commented Dec 6, 2019

@engineering87 had you run into this issue in practice, or were you just tackling it based on @mitchelsellers' issue #2868? It would be great if we could isolate and reproduce the real issue to make sure any change we make is truly helpful.

@engineering87
Copy link
Contributor Author

Actually just tackling it based on the #2868 issue but I will make further checks and tests to try to replicate what has been reported.

@mitchelsellers
Copy link
Contributor

From what I can tell. It appears that this is no longer an issue. It was recreatable when I submitted the issue, but I cannot now.

Copy link
Contributor

@donker donker left a comment

Choose a reason for hiding this comment

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

I actually find this code proposal better than what was there. It's more logical: first check if the value was previously set and only then check for a changed value, not the other way around.

Copy link
Contributor

@valadas valadas left a comment

Choose a reason for hiding this comment

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

Looks good to me

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