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

TaskResultConverter returns default value when task not set #4790

Merged
merged 4 commits into from
Oct 21, 2022

Conversation

michael-hawker
Copy link
Member

Fixes #4505

Adds better testing around real-world x:Bind and converter scenarios for TaskResultConverter, also related to the nature of how this interacts with the MVVM Toolkit behavior (which would mimic most real-world app behavior as well).

Fixes the converter to better handle a wider variety of scenarios.

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Documentation content changes

What is the current behavior?

The TaskResultConverter will return UnsetValue when the expected Task has not been initialized yet (and is null).

The documentation specified the default value would be returned, but this was not true for value types.

What is the new behavior?

TaskResultConverter now will return the default value (null or otherwise for value types) whether a task is set or not.

It'll also passthru non-task values as a no-op.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • Tested code with current supported SDKs
  • New component
    • Pull Request has been submitted to the documentation repository instructions. Link:
    • Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
    • If control, added to Visual Studio Design project
  • Sample in sample app has been added / updated (for bug fixes / features)
  • New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

See more details in accompanying issue.

@michael-hawker michael-hawker added bug 🐛 An unexpected issue that highlights incorrect behavior helpers ✋ labels Oct 20, 2022
@michael-hawker michael-hawker added this to the 7.1.3 milestone Oct 20, 2022
@ghost
Copy link

ghost commented Oct 20, 2022

Thanks michael-hawker for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@ghost ghost requested a review from azchohfi October 20, 2022 22:25
@michael-hawker michael-hawker requested review from Sergio0694 and Arlodotexe and removed request for azchohfi October 20, 2022 22:25
Copy link
Member

@Arlodotexe Arlodotexe left a comment

Choose a reason for hiding this comment

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

Couldn't find any issues with it, and checking around this seems to be the best approach. Approved!

@michael-hawker
Copy link
Member Author

@Sergio0694 had concerns on reflection bit for value type support. So instead updated the comment to reflect actual behavior (returning null) and took middle-ground approach for hotfix release.

Part of the discrepancy/confusion here is also due to the fact the base methods we use have slightly different behavior between the generic and non-generic versions from the TaskExtensions, so we may want to coordinate a resolution there if this doesn't solve the majority of common scenarios for folks. See: https://github.com/CommunityToolkit/dotnet/blob/main/CommunityToolkit.Common/Extensions/TaskExtensions.cs

Copy link
Member

@Sergio0694 Sergio0694 left a comment

Choose a reason for hiding this comment

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

Ship it! :shipit:

@ghost
Copy link

ghost commented Oct 20, 2022

Hello @michael-hawker!

Because this pull request has the auto merge :zap: label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

Do note that I've been instructed to only help merge pull requests of this repository that have been opened for at least 8 hours, a condition that will be fulfilled in about 6 hours 57 minutes. No worries though, I will be back when the time is right! 😉

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

…fault value in case task is not set or has not completed.

Updated description to include unset Task scenario (i.e. null being passed in)
Updated to include proper default value return for Value types
Included value passthru for non-Task values
Update description to explicitly call out returning null instead of default if no task or task result not ready.
@michael-hawker michael-hawker merged commit b22c115 into CommunityToolkit:main Oct 21, 2022
@michael-hawker michael-hawker deleted the llama/fix4505 branch October 21, 2022 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merge ⚡ bug 🐛 An unexpected issue that highlights incorrect behavior helpers ✋
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TaskResultConverter causes an InvalidCastException (can't cast COM object to T)
3 participants