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

Refactor ConventionDispatcher to allow delayed execution #7747

Merged
merged 1 commit into from
Mar 3, 2017

Conversation

AndriySvyryd
Copy link
Member

  • Refactor ConventionDispatcher
    • Allow delayed execution
    • Allow tracking the foreign key modified by conventions.
    • When set on ConventionDispatcher ConventionScope captures the conventions to be executed.
    • ConventionBatch sets a ConventionScope and executed the stored conventions when it's run or disposed.
    • When conventions captured in a ConventionScope are executed any triggered conventions are captured in a new ConventionScope to avoid keeping all the convention chain on the stack.
    • This changes the order of convention execution which exposed some issues in code and tests
  • Allow specifying the dependend end without specifying the FK properties,
  • Throw when the same property is specified several times when adding a key, foreign key or indexes.
  • Remove Mock usage from ConventionDispatcherTest

Part of #214

@AndriySvyryd
Copy link
Member Author

This change adds a visitor to run conventions, so from this point on @anpete will be able to contribute to the model building code 😄

{
return RunOnEntityTypeAdded(entityTypeBuilder);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider having a ConventionScope (or some sugar API) that doesn't batch to avoid having to do this conditional every place.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do

{
Run();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it OK to Run if an exception is thrown and Dispose happens as part of unwinding the stack?

Copy link
Member Author

Choose a reason for hiding this comment

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

The conventions should be robust enough to not throw even if the model is in a bad state due to an exception. All of our negative test cases work correctly. But in theory we should avoid running them after an exception, though I'd have to figure out how this can be detected.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine to leave as is unless we discover a real issue with it in practice.

private void Run()
{
_ran = true;
while (true)
Copy link
Contributor

Choose a reason for hiding this comment

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

while (true) [](start = 15, length = 13)

Could we avoid an infinite loop here by stopping (or at least warning) if this goes on for a very large number of iterations?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can throw. I don't think a warning will do much of a difference.
Is 65536 a reasonable limit?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would hope so...

Copy link
Member Author

Choose a reason for hiding this comment

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

The exception message would be

The convention invocations have reached the recursion limit. This is likely an issue in EF Core, please report it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Add a fwdlink for where to report it? @rowanmiller Maybe also suggest to include repro code and version of EF being used--we could include the version in this message.

Copy link
Contributor

@ajcvickers ajcvickers left a comment

Choose a reason for hiding this comment

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

🐑 🇮🇹

/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public Reference([CanBeNull] T @object, [CanBeNull] IReferenceRoot<T> root)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this CanBeNull true? Other constructor and setter has notnull

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, the other one CanBeNull as well

@@ -8,6 +8,7 @@
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal;
Copy link
Contributor

Choose a reason for hiding this comment

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

sort using in all files

Copy link
Member Author

Choose a reason for hiding this comment

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

yup

@smitpatel
Copy link
Contributor

:shipit:

@smitpatel
Copy link
Contributor

Now conventions are even more magic :trollface:

@AndriySvyryd
Copy link
Member Author

@smitpatel I think of it more as rule enforcement for conventions, so they will become regulated magic
Proper Unicorn

@AndriySvyryd AndriySvyryd force-pushed the ConventionsWorkflow branch from 037cd41 to cc24376 Compare March 3, 2017 01:04
…ns and tracking objects modified by conventions.

  When set on ConventionDispatcher ConventionScope captures the conventions to be executed.
  ConventionBatch sets a ConventionScope and executed the stored conventions when it's run or disposed.
  When conventions captured in a ConventionScope are executed any triggered conventions are captured in a new ConventionScope to avoid keeping all the convention chain on the stack.
  This changes the order of convention execution which exposed some issues in code and tests
Allow specifying the dependend end without specifying the FK properties,
Throw when the same property is specified several times when adding a key, foreign key or indexes.
Remove Mock usage from ConventionDispatcherTest

Part of #214
@AndriySvyryd AndriySvyryd force-pushed the ConventionsWorkflow branch from cc24376 to 1243426 Compare March 3, 2017 19:44
@AndriySvyryd AndriySvyryd merged commit 1243426 into dev Mar 3, 2017
@AndriySvyryd AndriySvyryd deleted the ConventionsWorkflow branch March 3, 2017 19:46
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.

4 participants