Skip to content

CSHARP-3399: Mitigate pain of using field names with dots and dollars. #568

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

Merged
merged 3 commits into from
Jul 13, 2021

Conversation

JamesKovacs
Copy link
Contributor

We can't remove these validators completely as we still need to validate that updates contain a $OP at the root and that replacements do not contain $FIELD at the root. MongoDB 5.0 allows inserts of $FIELD at the root but not replacements.

As well we have logic in UpdateMessageBinaryEncoder.cs line 145 where we use the validator type to check for a valid message:

                if (updateValidator is UpdateElementNameValidator && binaryWriter.BaseStream.Position == position + 5)
                {
                    throw new BsonSerializationException("Update documents cannot be empty.");
                }

This is existing code and I didn't want to rewrite the logic at this point.

The spec test refreshes are required because the old tests were depending on inserting documents of the form { ".": 1 } to throw a client-side BSON serialization error, which they no longer do.

There are still EG test failures that I'm working through. So far they all appear to be due to test problems like the spec test refreshes mentioned above. I'll push additional commits to this PR as I fix them.

@JamesKovacs JamesKovacs requested a review from jyemin July 12, 2021 15:59
@jyemin jyemin requested review from rstam and removed request for jyemin July 12, 2021 16:12
Copy link
Contributor

@rstam rstam left a comment

Choose a reason for hiding this comment

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

Looks good though it seemed to me it could be even a bit simpler.

Take a look at the comments and let me know what you think.

{
return false;
}

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 we can leave this class alone (no changes) and instead just stop using it.

Copy link
Contributor

Choose a reason for hiding this comment

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

In FindOneAndReplaceOperation delete the nested Validator class and refactor GetCommandValidator to:

protected override IElementNameValidator GetCommandValidator()
{
    return NoOpElementNameValidator.Instance;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

In RetryabelInsertCommandOperation replace line 137 with:

 var elementNameValidator = NoOpElementNameValidator.Instance;

Copy link
Contributor

Choose a reason for hiding this comment

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

In InsertMessageBinaryEncoder replace line 147 with:

var elementNameValidator = NoOpElementNameValidator.Instance;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed via Slack. My initial concern was end users depending on CollectionElementNameValidator throwing an ArgumentNullException whereas NoOpElementNameValidator does not. Upon reflection, all validators should throw an ArgumentNullException because many will throw a NullReferenceException if called with a null element name.

With this in mind, I was able to replace usages of CENV with NOENV, which simplified a few code paths.


// public static fields
/// <summary>
/// Gets a pre-created instance of an UpdateElementNameValidator.
Copy link
Contributor

Choose a reason for hiding this comment

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

/// Gets a pre-created instance of an ReplacementElementNameValidator.

Copy link
Contributor

@rstam rstam left a comment

Choose a reason for hiding this comment

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

LGTM

@JamesKovacs JamesKovacs merged commit ced67a1 into mongodb:master Jul 13, 2021
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.

2 participants