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

Stop including the discriminator in the JSON id by default #34208

Merged
merged 4 commits into from
Aug 2, 2024

Conversation

ajcvickers
Copy link
Contributor

Fixes #34179

There are also new APIs on the entity type and model builders to facilitate optional behaviors, including reverting to the pre-9 behavior:

  • Entity().IncludeDiscriminatorInJsonId();
  • Entity().IncludeRootDiscriminatorInJsonId();
  • Entity().AlwaysCreateShadowIdProperty();

Note that this change requires regeneration of the Northwind database.

@ajcvickers ajcvickers requested a review from a team July 11, 2024 13:58
Copy link
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

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

How do we make sure that the Northwind database is recreated on the CI with the new values and is also correctly recreated with the old values when code from an older branch runs?

@roji
Copy link
Member

roji commented Jul 13, 2024

How do we make sure that the Northwind database is recreated on the CI with the new values and is also correctly recreated with the old values when code from an older branch runs?

IMHO that's another good reason to not rely on a persistent database in CI, but rather to just use the emulator, where it's guaranteed to be recreated each time (I think we agreed we want to go in that direction anyway, possibly except for specific RBAC tests which can't be executed with the emulator?).

If we do want to stay with non-emulator tests, we could simply recreate the database each time, but on Ci only (to avoid making local runs slow), e.g. by checking the CI environment variable.

@AndriySvyryd
Copy link
Member

IMHO that's another good reason to not rely on a persistent database in CI, but rather to just use the emulator, where it's guaranteed to be recreated each time (I think we agreed we want to go in that direction anyway, possibly except for specific RBAC tests which can't be executed with the emulator?).

We need to do #19973 first

If we do want to stay with non-emulator tests, we could simply recreate the database each time, but on Ci only (to avoid making local runs slow), e.g. by checking the CI environment variable.

That would still not work for tests from old branches. We'd need to rename the database.

@ajcvickers
Copy link
Contributor Author

@roji @AndriySvyryd New version up attempting to follow Andriy's guidance.

@ajcvickers ajcvickers requested review from AndriySvyryd, roji and a team July 18, 2024 17:10
@ajcvickers ajcvickers force-pushed the NormalForNorfolk branch 4 times, most recently from bc508ac to 0c548b5 Compare July 23, 2024 17:00
@ajcvickers
Copy link
Contributor Author

@roji This is now updated with fixes for discriminator checking and more tests. Can you check the test baselines to make sure you think we are doing ReadItem or not as appropriate? I commented on each test case where we don't do ReadItem indicating why not for that case.

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

Hey, here's a review of the ReadItemPartitionKey tests only. The actual behavior seems correct to me (i.e. I haven't noticed a case where we do ReadItem when we shouldn't or vice versa). So below see mainly some comments about the structure/factoring of these tests.

As a general comment, there's maybe a bit more systematic duplication of tests across various scenarios than I'd have personally done... This is definitely a matter of personal style/taste on how to test: more black box-style "cover all permutations" vs. more white-box "think about specific scenarios you want/need to cover" (I lean much more in the latter direction). For example, do we think we need all the duplication along the only/non-only axis, as well as everything on the leaf. I'm also noting that there seem to be relatively few tests which actually differ across the different implementations (e.g. HierarchicalPartitionKeyEntity is practically identical across all versions).

But I think it's all OK, hopefully it doesn't cost us in terms of maintainability/complexity.

Regardless FYI it took me a while to understand all the test factoring here and realize what extends from what and why :) It makes sense to me now, but maybe a comment on each test class to explain what it's there for could be useful for our future selves.

@@ -100,6 +100,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
{
base.OnModelCreating(modelBuilder, context);

modelBuilder.IncludeDiscriminatorInJsonId();
Copy link
Member

Choose a reason for hiding this comment

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

Any specific reason to do this on this specific test suite (not pushing back)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because otherwise the test data results in conflicts in the JSON id values.

Copy link
Member

Choose a reason for hiding this comment

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

Given we're gonna have so many ReadItemPartitionKey query tests, maybe they deserve their own sub-folder...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you asking me to put them in a subfolder? Happy to do so, if that's what you want.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that was the idea


// Not ReadItem because no primary key value
Copy link
Member

Choose a reason for hiding this comment

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

Also just additional things in predicate

@ajcvickers
Copy link
Contributor Author

As a general comment, there's maybe a bit more systematic duplication of tests across various scenarios than I'd have personally done... This is definitely a matter of personal style/taste on how to test: more black box-style "cover all permutations" vs. more white-box "think about specific scenarios you want/need to cover" (I lean much more in the latter direction).

I very much believe that if I only do "white box" testing, then I will ship significantly more bugs. This is based on my experience of writing tests in this way and frequently finding a bug in a scenario I had never even thought of. So, at least for people of my ability, this will be a trade off for the advantages of having fewer tests against us shipping more bugs.

@ajcvickers ajcvickers requested a review from roji July 28, 2024 11:26
@ajcvickers ajcvickers force-pushed the NormalForNorfolk branch 2 times, most recently from f813158 to ff8e1e7 Compare July 28, 2024 13:27
Copy link
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

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

There aren't any blocking issues

roji and others added 3 commits August 2, 2024 12:30
Fixes #34179

There are also new APIs on the entity type and model builders to facilitate optional behaviors, including reverting to the pre-9 behavior:

- Entity<Blog>().IncludeDiscriminatorInJsonId();
- Entity<Blog>().IncludeRootDiscriminatorInJsonId();
- Entity<Blog>().AlwaysCreateShadowIdProperty();

Note that this change requires regeneration of the Northwind database.
@ajcvickers ajcvickers merged commit 41e511f into main Aug 2, 2024
7 checks passed
@ajcvickers ajcvickers deleted the NormalForNorfolk branch August 2, 2024 15:36
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.

Cosmos: Use 1:1 mapping for .NET Id to JSON id unless explicitly configured otherwise
3 participants