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

DYN-7278: Fix dictionary preview by adding support for more types #15750

Merged
merged 9 commits into from
Jan 14, 2025

Conversation

aparajit-pratap
Copy link
Contributor

@aparajit-pratap aparajit-pratap commented Jan 10, 2025

Purpose

Fixes for previewing dictionaries containing UInt32, UInt64, Byte, and NewtonSoft.Json.Linq.JObject types. The latter is needed to support previewing Forma nodes currently as those are the output types generated for some nodes.

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

Node preview fixes for dictionaries containing certain types.

Reviewers

(FILL ME IN) Reviewer 1 (If possible, assign the Reviewer for the PR)

(FILL ME IN, optional) Any additional notes to reviewers or testers.

FYIs

(FILL ME IN, Optional) Names of anyone else you wish to be notified of

@github-actions github-actions bot changed the title fix dictionary preview by adding support for more types DYN-7278: fix dictionary preview by adding support for more types Jan 10, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

See the ticket for this pull request: https://jira.autodesk.com/browse/DYN-7278

Copy link

github-actions bot commented Jan 10, 2025

UI Smoke Tests

Test: success. 11 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests

@@ -122,6 +135,28 @@ private WatchViewModel ProcessThing(object value, ProtoCore.RuntimeCore runtimeC
return new WatchViewModel(value, tag, RequestSelectGeometry);
}

private static Dictionary<string, object> ConvertJObjectToDictionary(JObject jObject)
Copy link
Member

@mjkkirschner mjkkirschner Jan 10, 2025

Choose a reason for hiding this comment

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

a couple thoughts.

  1. If I am understanding correctly, this is essentially arbitrary deserialization of json using the ToObject() calls. It's not clear to me exactly what types this allows deserialization of.

I think the default deserialization calls use a secure serializer (TypeNameHandling = None), but I am not sure, it might be good to make it explicit by using a serializer here with settings that encode that specifically - for example:

TypeNameHandling = TypeNameHandling.None,

IMO this kind of thing becomes more important now that we have to support DaaS - though I guess maybe this code is never even present on the service? (wpf?)

  1. Where is this type coming from? The Forma nodes? Personally I feel we should ditch newtonsoft everywhere and instead use the built in system.text.json - it's harder to screw up security using it (though not impossible)

  2. I have not thought about it much - but wouldn't it be nice if packages could provide their own watch handlers?

  3. why are both dictionary and this newtonsoft parsing done in the object handler instead of defining more specific overloads - was there a performance reason for this?

Copy link
Contributor Author

@aparajit-pratap aparajit-pratap Jan 11, 2025

Choose a reason for hiding this comment

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

  1. These are NewtonSoft.Json JObject types that are coming mainly from Forma elements represented as JSON. As of now, I'm not sure what other nodes exist that output such types that have preview issues but so far, I'm seeing this issue only with the Forma nodes. The JObject seems to have a structure similar to dictionaries or key-value pairs so it just seems natural to be able to convert them to a form such that they can be previewed such as dictionaries.
  2. Yes, to types coming from Forma. I'll see if I can switch the deserialization to use System.Text.Json instead but I think it would mean changing the DynamoForma package to use STJ as well. If that's the case, that would be out of scope for this fix.
  3. Not sure given that I think this is the first time we've encountered a case such as this where nodes in a package are having preview issues and therefore such cases seem to be rare but still open to discuss.
  4. I'm not sure I understand. What exactly are you referring to by object handler and overloads?
    I think I see what you mean. No particular reason for doing it this way. I can add an overload for ProcessThing to handle JObject and maybe another for Dictionary, if that's what you're alluding to.

Copy link
Contributor

Choose a reason for hiding this comment

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

These changes seem to be the first step in trying to support NewtonSoft types as native dynamo types.
If JObjects are passed around between nodes, do you foresee any other nodes/functionality that might not work with this type?

If we want to favor more system.text.json instead of Newtonsoft, I assume we'll encounter similar system.text.json types (like JsonElement and JSonDocument). Should we try to support these at the Proto level in the Marshaler code?

Copy link
Contributor

Choose a reason for hiding this comment

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

I kind of like the packages could provide their own watch handlers? idea. Some packages might bring their own magic types, and would be nice if they could specify the way Dynamo presents the data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pinzart90 these changes are only affecting the node previews for these types at the UI level and are not related to marshaling types so in that sense IMO these changes are safer. In order to support System.Text.Json, yes, I believe we'll need to add support for it here as well although I don't think anything specific would need to be done in the marshaler.

case TypeCode.UInt32:
return nameof(TypeCode.UInt32);
case TypeCode.UInt64:
return nameof(TypeCode.UInt64);
Copy link
Contributor Author

@aparajit-pratap aparajit-pratap Jan 11, 2025

Choose a reason for hiding this comment

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

I don't believe the type returned from GetDisplayType is actually being used currently so it might just be better to remove this function for the time being.

@aparajit-pratap aparajit-pratap changed the title DYN-7278: fix dictionary preview by adding support for more types DYN-7278: Fix dictionary preview by adding support for more types Jan 14, 2025
Copy link
Contributor

@pinzart90 pinzart90 left a comment

Choose a reason for hiding this comment

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

The only reason I would see to delay this PR would be to make the WatchHandler formatting customizable in the 3d party packages. But that seems out of scope.
So LGTM

@aparajit-pratap
Copy link
Contributor Author

The only reason I would see to delay this PR would be to make the WatchHandler formatting customizable in the 3d party packages. But that seems out of scope. So LGTM

Yes, sorry for not making that clear. I intend to do that investigation separately outside this PR's scope. Thanks.

@aparajit-pratap aparajit-pratap merged commit 2636f7f into DynamoDS:master Jan 14, 2025
27 of 28 checks passed
@aparajit-pratap aparajit-pratap deleted the dyn-7278 branch January 14, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants