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-1476: AllowRankReductionAttribute on Zero Touch seems to be broken #9542

Merged
merged 15 commits into from
Mar 7, 2019

Conversation

scottmitchell
Copy link
Collaborator

Purpose

Jira issue DYN-1476.

This PR addresses a bug where the AllowRankReductionAttribute does not work for Zero Touch properties. The typical use case for the AllowRankReductionAttribute is to reduce the rank of the return value of methods—rather than return a list of a single item, the method will return just the item. This does not currently work for properties because a property's attributes are not automatically applied to that property's getter (which is what actually get's invoked by the Zero Touch node). For example, this does not currently result in rank reduction of the get_SomeProperty return value:

[AllowRankReduction] // This won't have any effect
public List<object> SomeProperty => new List<object> { someObject };

A work around is possible by explicitly declaring the getter with AllowRankReductionAttribute:

[AllowRankReduction]
public List<object> SomeProperty2
{
    [AllowRankReduction] // Adding this one will make it work
    get
    {
         return new List<object> { someObject };
    }
}

There are a couple possible solutions here:

Solution 1: Change nothing, and simply message to users that they must explicitly declare getters if they want to use this attribute. However, this behavior could be confusing to a Zero Touch developer.

Solution 2: Copy the attribute from the property to its getter at runtime—that could happen here. This may be possible, but certainly isn't trivial. Some info on that here: https://stackoverflow.com/questions/14663763/how-to-add-an-attribute-to-a-property-at-runtime

Solution 3: Add another rank reduction check later in the function invoke process, where the property attributes are available—maybe here.

Solution 4 (this PR): Create a way to pass the property's AllowRankReductionAttribute down to the FFIMemberInfo instance created from the getter, without actually adding the attribute to the getter. This seems to be the least invasive way to add this functionality to Zero Touch properties. However, it may not be the cleanest.

Declarations

Check these if you believe they are true

  • The code base 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.

Reviewers

@aparajit-pratap @mjkkirschner

FYIs

@QilongTang

@aparajit-pratap
Copy link
Contributor

@scottmitchell I think this is a clean and simple solution! I would "LGTM" this after some tests :)
Thanks!

@@ -64,6 +64,26 @@ protected FFIMemberInfo(MemberInfo info)
Info = info;
}

internal void CheckForRankReductionAttribute(Dictionary<MethodInfo, Attribute[]> getterAttributes)
Copy link
Member

Choose a reason for hiding this comment

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

name is okay to me, but just considering others - copyRankReductionAttribute?

Copy link
Contributor

Choose a reason for hiding this comment

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

Would you add some function comments, what you have mentioned in this PR description is good enough

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@QilongTang yes, I'll add some comments. @mjkkirschner yeah I like that better. Or maybe "AttachRankReductionAttribute"

@mjkkirschner
Copy link
Member

mjkkirschner commented Mar 5, 2019

it looks good to me, lets add some tests.

@QilongTang
Copy link
Contributor

LGTM with a few comments and looking forward to tests

@aparajit-pratap
Copy link
Contributor

@scottmitchell you can add dummy test classes and methods/properties to FFITarget project. It's a test zero touch library we use in our FFI (Foreign Function Interface) tests.

@scottmitchell
Copy link
Collaborator Author

Thanks @aparajit-pratap, I was going to ask about that

@@ -784,7 +784,7 @@ private void RegisterFunctionPointer(string functionName, MemberInfo method, Lis
else if (CoreUtils.IsGetter(functionName))
{
f = new GetterFunctionPointer(Module, functionName, method, retype);
(f as GetterFunctionPointer).ReflectionInfo.CheckForRankReductionAttribute(mGetterAttributes);
(f as GetterFunctionPointer).ReflectionInfo.CopyRankReductionAttribute(mGetterAttributes);
Copy link
Contributor

@aparajit-pratap aparajit-pratap Mar 7, 2019

Choose a reason for hiding this comment

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

Sorry, but I think the earlier name was more appropriate considering the context in which it is used. It first checks and then only copies.

@@ -457,4 +457,35 @@ public void Dispose()
}
}

public class TestRankReduce : IDisposable
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to make this class an IDisposable.

Copy link
Member

Choose a reason for hiding this comment

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

did you intend to dispose this class?

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 only implemented IDisposable because the other test objects in this file did. I didn't really have any intentions for it.

private string RankReduceTestField;

[AllowRankReduction]
public List<string> RankReduceArrowProperty => new List<string> { RankReduceTestField };
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this syntax different from the RankReducePropertyGetter?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's just syntactic sugar for the getter. Testing one of these would suffice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fair enough. I just carried this over from the test cases I used during development. I removed the arrow property and added a method test (not sure if this exists anywhere else).

@aparajit-pratap
Copy link
Contributor

@scottmitchell some minor comments and then LGTM!

@mjkkirschner
Copy link
Member

why are the builds failing here?

@QilongTang
Copy link
Contributor

@mjkkirschner The console shows all clear 18 smoke tests pass and all good, ever see this happens?

@mjkkirschner
Copy link
Member

all checks clear 👍

@scottmitchell
Copy link
Collaborator Author

@aparajit-pratap @mjkkirschner @QilongTang Thanks for your alls comments. I think I've addressed everything—Let me know if I haven't. Otherwise, I'll go ahead and merge once the checks pass.

@QilongTang QilongTang added the LGTM Looks good to me label Mar 7, 2019
@QilongTang QilongTang changed the title [WIP] [PTAL] DYN-1476: AllowRankReductionAttribute on Zero Touch seems to be broken DYN-1476: AllowRankReductionAttribute on Zero Touch seems to be broken Mar 7, 2019
@scottmitchell scottmitchell merged commit 0dbc0cc into DynamoDS:master Mar 7, 2019
@mjkkirschner
Copy link
Member

@scottmitchell please send a cherry pick if this is labeled 2.2

scottmitchell added a commit to scottmitchell/Dynamo that referenced this pull request Mar 7, 2019
DynamoDS#9542)

* update

* Brought truncated search results and full query search out from behind debug menu. Deleted debug menu items.

* Added CheckForRankReductionAttribute() method to FFIMemberInfo

* Cleaned up CheckForRankReductionAttribute

* Added AllowRankReductionAttribute tests

* Comments. Change method name.

* Update tests, method name

* Corrected test names

* Fixed annoying diff
scottmitchell added a commit that referenced this pull request Mar 8, 2019
…rties (#9542) (#9549)

* DYN-1476: AllowRankReductionAttribute on Zero Touch seems to be broken (#9542)

* update

* Brought truncated search results and full query search out from behind debug menu. Deleted debug menu items.

* Added CheckForRankReductionAttribute() method to FFIMemberInfo

* Cleaned up CheckForRankReductionAttribute

* Added AllowRankReductionAttribute tests

* Comments. Change method name.

* Update tests, method name

* Corrected test names

* Fixed annoying diff

* DYN-1476 Follow Up: Remove Rank Reduction from Dictionary.Values (#9550)

* update

* Brought truncated search results and full query search out from behind debug menu. Deleted debug menu items.

* Removed AllowRankReduction from Dictionary.Values. Added TODO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LGTM Looks good to me
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants