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

Pm violation fix #14506

Closed
wants to merge 12 commits into from
Closed

Pm violation fix #14506

wants to merge 12 commits into from

Conversation

dnenov
Copy link
Collaborator

@dnenov dnenov commented Oct 22, 2023

Purpose

The main issue was resolved inside PR .This PR will be closed in favor of the following separate PRs:

This is an urgent PR to address a crash when inputting text in the search box of the new Package Manager.

The issue was found to be the inappropriate placement of the LuceneUtility.DisposeAll() clean-up code inside the Close method of the PackageManagerSearchViewModel class. The View Model persists in between sessions, or uses of the Package Manager. Only the View is closed. The method Close was used to reset the state of the View (cleaning loading progress, search bar text, etc). When using the LuceneUtility.DisposeAll() without disposing of the View Model, we would create the conditions for the crash on subsequent restarts of the View.

  • LuceneUtility.DisposeAll() was removed
  • Close was renamed to PackageManagerViewClose to avoid further confusion

Other binding issues:

  • AmbiguousMatchException error fixed - using the public new PackageManagerSearchElement **Model** inside the PackageManagerSearchElementViewModel was the cause of the bug. Model was hiding the base class Model property, during reflection WPF was finding both and reporting AmbiguousMatchException.
  • other binding issues resolved

No issues when interacting with the new PM

ambigous bug fix

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated
  • This PR contains no files larger than 50 MB

Release Notes

  • located the issue causing a crash when input text into the search box
  • LuceneUtility.DisposeAll(); was called in the Close() method of the PackageManagerSearchViewModel. The Close() method was used to 'reset' values used by the PackageManagerView between sessions. Since the PackageManagerSearchViewModel itself is not distroyed, but persists between PM sessions (old design pattern, cached search results one reason to keep the VM) LuceneUtility.DisposeAll() should not have been disposed of
  • the 'Close()' method was removed in favor of PackageManagerViewClose() to avoid confusion
  • multiple binding issues resolved
  • AmbiguousMatchException fixed
  • hiding the base class 'Model' peroperty, by using the public new PackageManagerSearchElement Model inside the PackageManagerSearchElementViewModel was the cause of the bug. This is a legacy code and the issue must have been present all along
  • renaming the Model to SearchElementModel fixes the issue
  • also created ViewModel properties corresponding to the Model properties for View binding

Reviewers

@mjkkirschner
@QilongTang

FYIs

@Amoursol

- located the issue causing a crash when input text into the search box
- LuceneUtility.DisposeAll(); was called in the Close() method of the PackageManagerSearchViewModel. The Close() method was used to 'reset' values used by the PackageManagerView between sessions. Since the PackageManagerSearchViewModel itself is not distroyed, but persists between PM sessions (old design pattern, cached search results one reason to keep the VM) LuceneUtility.DisposeAll() should not have been disposed of
- the 'Close()' method was removed in favor of PackageManagerViewClose() to avoid confusion
- multiple binding issues resolved
- keep resolving binding issues
- hiding the base class 'Model' peropert, by using the `public new PackageManagerSearchElement Model` inside the PackageManagerSearchElementViewModel was the cause of the bug. This is a legacy code and the issue must have been present all along
- renaming the Model to SearchElementModel fixes the issue
- also created ViewModel properties corresponding to the Model properties for View binding
@mjkkirschner mjkkirschner added this to the 3.0 milestone Oct 23, 2023
Copy link
Member

@mjkkirschner mjkkirschner left a comment

Choose a reason for hiding this comment

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

  1. some feedback
  2. are these changes all related to these fixes, it looks like maybe there are some extra commits in here?
  3. more tests please!
  4. looks like a merge conflict.

src/DynamoCoreWpf/Controls/InstalledPackagesControl.xaml Outdated Show resolved Hide resolved
src/DynamoCoreWpf/UI/Converters.cs Show resolved Hide resolved
@@ -569,7 +569,7 @@ internal static void ExecuteViewDetailsSideBar(Step stepInfo, StepUIAutomation u
if (packageManagerSearchElementViewModel == null) return;

if (packageDetailsWindow == null)
packageManagerViewModel.ViewPackageDetailsCommand.Execute(packageManagerSearchElementViewModel.Model);
packageManagerViewModel.ViewPackageDetailsCommand.Execute(packageManagerSearchElementViewModel.SearchElementModel);
Copy link
Member

Choose a reason for hiding this comment

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

whats the difference between the Model and SearchElementModel - I would definitely also have thought the model was the appropriate parameter for this command?

Does the type checking or documentation for the command need to be improved?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no difference between Model and SearchElementModel. The name Model was causing a AmbiguousMatchException error, as it was hiding the Model of the base class, thus causing the ambiguity. Renaming the property solved that issue.

@@ -21,7 +21,46 @@ public class PackageManagerSearchElementViewModel : BrowserItemViewModel, IEquat
public ICommand VisitRepositoryCommand { get; set; }
public ICommand DownloadLatestToCustomPathCommand { get; set; }

public new PackageManagerSearchElement Model { get; internal set; }
Copy link
Member

Choose a reason for hiding this comment

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

oh I see, you removed it and the new keyword...what was it hiding?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, exactly! It was hiding it.

/// <summary>
/// The PackageManagerSearchElement Model this VM links to
/// </summary>
public PackageManagerSearchElement SearchElementModel { get; internal set; }
Copy link
Member

Choose a reason for hiding this comment

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

so this is really the model?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the Model model .. yes :/ I came up with this name to avoid the Ambiguity.

/// <summary>
/// VM IsDeprecated property
/// </summary>
public bool IsDeprecated { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

so why do we need all these now? Were we binding to the model directly before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We were binding directly to the Model. We had a discussion with @QilongTang a while back to move the binding to the VM, but left it for another day. I took the opportunity to do it with this PR.

/// <summary>
/// Sets the VM properties to be bound to
/// </summary>
private void SetModelProperties()
Copy link
Member

Choose a reason for hiding this comment

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

this method name seems backwards to me, isn't this setting ViewModel properties from the model?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

SetViewModelProperties sounds more suitable, I will change that!

/// </summary>
private void SetModelProperties()
{
IsDeprecated = this.SearchElementModel.IsDeprecated;
Copy link
Member

Choose a reason for hiding this comment

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

maybe these properties should just be getters to the model directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got it! Will give it a try and rework those.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, @mjkkirschner , got them as getters to the model now! Thank you for the prompt.

/// </summary>
internal void Close()
internal void PackageManagerViewClose()
Copy link
Member

Choose a reason for hiding this comment

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

is this a handler? Maybe it should be called OnPackageManagerViewClose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is actively called from inside the View when the View is about to close. I don't know if the VM has handle on the View to subscribe to an event, if so I can flip it around, as in subscribe to the View Closing or Closed event.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I checked, and the view model does not reference the view. Would that be an acceptable solution?

@@ -43,24 +43,25 @@ public string Watermark
new FrameworkPropertyMetadata("0"));

// The Value of the numerical up/down control. Bind to this property
public int Value
public string Value
Copy link
Member

Choose a reason for hiding this comment

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

what is this used for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a Number up/down slider custom control (wpf does not have one out of the box that does what we need. We used a library one, but discarded that to avoid reliance on that library, if you remember? that's the same control)
Having the property as an int was causing a conversion error that was difficult to navigate out of, for me at least. Having the property as a string simplifies this and serves the need, which is to display the number as a text, better.

Copy link
Member

Choose a reason for hiding this comment

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

@dnenov when publishing a new version where is this string converted to a number? At least I am assuming that a number is needed in the request for the version information?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The properties of the PublishPackageViewModel, and they are also strings. https://github.com/DynamoDS/Dynamo/blob/master/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs#L294 It gets used in the BuildPackage https://github.com/DynamoDS/Dynamo/blob/master/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs#L1646, so it's strings all the way really. But there is an int check built inside those properties.

@mjkkirschner mjkkirschner added the crash Related to a crash. label Oct 23, 2023
- removed an old conversion that seems to no longer be necessary
- added converter test for the DateToPackageLabelConverter
- reworked the view model properties
@dnenov
Copy link
Collaborator Author

dnenov commented Oct 25, 2023

I think was able to address all the comments @mjkkirschner . The PR is working a bit harder than addressing the crash only, I hope that's OK.

@mjkkirschner
Copy link
Member

@dnenov can you please resolve the conflict here

{
TimedOut = false; // reset the timedout screen
InitialResultsLoaded = false; // reset the loading screen settings
RequestShowFileDialog -= OnRequestShowFileDialog;
nonHostFilter.ForEach(f => f.PropertyChanged -= filter_PropertyChanged);
LuceneUtility.DisposeAll();
Copy link
Member

Choose a reason for hiding this comment

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

@QilongTang @reddyashish I think you should take a look at this. Should this be called from somewhere else, in this case @dnenov found that calling DisposeAll caused an access violation the next time you try to start the PackageManager View.

Instead of just being removed, should this be moved to shutdown/dispose of the PackageManagerViewExtension or DynamoView? IE somewhere higher up than the PackageManagerSearchView.

I also want to make sure we're not now leaking indexing data if we open and close the package manager search view over and over.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method was not meant to be a Dispose method for the PackageManagerSearchViewModel, and I am sorry that I might have mislead someone with the naming. The PackageManagerSearchViewModel is not being destroyed once created inside the DynamoView .. I suppose it is garbage collected once Dynamo closes? If LuceneUtility needs to be disposed of .. I don't know, I couldn't figure out what exactly it is disposing of, I only know that if it was disposed then, on subsequent PM view creation, it would crash.

Copy link
Member

Choose a reason for hiding this comment

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

yes, I understand that this is not the dispose method, but it seems someone thought it was, I'm not sure who added this lucene dispose call, so I want to make sure that we don't need to find another place to relocate it to.

@dnenov dnenov mentioned this pull request Nov 2, 2023
9 tasks
@dnenov dnenov marked this pull request as draft November 2, 2023 14:12
@dnenov
Copy link
Collaborator Author

dnenov commented Nov 2, 2023

Closing this PR. All the original intended changes were disseminated over a number of smaller PRs. The main issue has been resolved in a separate PR (everything in the description above).

@dnenov dnenov closed this Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Related to a crash.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants