X Tutup
The Wayback Machine - https://web.archive.org/web/20240110133340/https://github.com/PowerShell/PowerShell/pull/20915
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 completion crash for the SCCM provider #20915

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

MartinGC94
Copy link
Contributor

PR Summary

Supersedes #20815 and actually fixes the issue this time:
image

It turns out that the SCCM provider returns the items as strings and adds all the various PS* properties as NoteProperties and none of the PS* properties include the actual value, see:
image

PR Context

Fixes #20803 (for real this time)

PR Checklist

// but some providers don't have it (like the Variable provider)
// So we use a substring of "PSPath" instead.
string childName = psObject.PSPath ?? string.Empty;
if (((PSObject)psObject).BaseObject is string result)
Copy link
Collaborator

@iSazonov iSazonov Dec 13, 2023

Choose a reason for hiding this comment

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

Have you considered PSObject.Base(psObject)?
Do we really need the cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No I didn't consider that. I've looked at the Base method and it does some unnecessary checks that makes it slower than just casting it. And I think the cast is needed because how else would I check that it's a string?

Copy link
Collaborator

Choose a reason for hiding this comment

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

how else would I check that it's a string?

psObject is dynamic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Elaborate please, I don't understand how the code would be written. Are you saying that: psObject is string result (where psObject is the variable name) would work the same way as the current code? My understanding is that I need to unwrap the PSObject before I can do the type check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think if ((psObject.BaseObject is string result) should work because old code was string childName = psObject.PSPath ?? string.Empty; - without cast.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just tested it and it does not seem to work. I guess it's because the dynamic implementation on PSObject only looks for members on the unwrapped object with no fallback to the original PSObject properties. My psObject is string result idea also doesn't work.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just tested it and it does not seem to work.

I wonder that string childName = psObject.PSPath ?? string.Empty; work. Exactly works? Or it is bug?
Maybe follow works:

object tmp = psObject.BaseObject;
if (tmp is string result)
...

I don't understand difference between psObject.PSPath and psObject.BaseObject. PSPath says that psObject is always PSObject. Why do we define it as dynamic?
I tend to think that this code either doesn't work correctly or it's too gimmicky and at the very least needs refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder that string childName = psObject.PSPath ?? string.Empty; work. Exactly works? Or it is bug?

The null check can probably be removed. I don't remember why I put it there but if it's null then there's something wrong so it's better to just throw.

I don't understand difference between psObject.PSPath and psObject.BaseObject. PSPath says that psObject is always PSObject. Why do we define it as dynamic?

It's so we can access the dynamic members more easily. We could make it a PSObject and use the appropriate properties/methods to access those members but the old code used dynamic so I figured it was fine to use here during the rewrite.

@daxian-dbw daxian-dbw added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Dec 13, 2023
@daxian-dbw
Copy link
Member

daxian-dbw commented Dec 13, 2023

@MartinGC94 #20815 was already merged, can you please rebase this PR against the master branch, so it's easier to see the changes on top?

@daxian-dbw
Copy link
Member

@MartinGC94 Thanks for rebasing. A question before moving on to review the code: are the changes from #20815 still relevant? I assume those changes are relevant to the fix and should be kept but want you to confirm.

@MartinGC94
Copy link
Contributor Author

MartinGC94 commented Dec 13, 2023

@daxian-dbw They are not. I tried reverting them with ab72ca7 but I don't see that in the changes overview https://github.com/PowerShell/PowerShell/pull/20915/files so I must be doing something wrong.

GitHub
PR Summary Supersedes #20815 and actually fixes the issue this time:

It turns out that the SCCM provider returns the items as strings and adds all the various PS* properties as NoteProperties and ...

@daxian-dbw
Copy link
Member

daxian-dbw commented Dec 13, 2023

They are not. I tried reverting them with ab72ca7 but I don't see that in the changes overview

Thanks for confirming. I submitted the #20919 to revert them then. Once the reverting PR is merged, please rebase this one again.

[Update] The reverting PR was merged: #20919

Copy link

This PR has 7 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Small
Size       : +6 -1
Percentile : 2.8%

Total files changed: 1

Change summary by file extension:
.cs : +6 -1

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@daxian-dbw
Copy link
Member

@alexlarner could you please try this fix again and see if it solves the problem? Thanks!

@alexlarner
Copy link

@alexlarner could you please try this fix again and see if it solves the problem? Thanks!

Yep, that did the trick. Thanks!

@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Dec 22, 2023
Copy link
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Extra Small Review - Needed The PR is being reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function & Cmdlet Name Tab Completion Broken in the ConfigManager (CMSITE) Provider
4 participants
X Tutup