-
Notifications
You must be signed in to change notification settings - Fork 229
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
Fix S6966 FP: MongoDB Find can not be replaced by FindAsync #9265
Comments
Thank you @ahusseini this is a known problem for Mongo DB's API design and has already been documented for the rule: sonar-dotnet/analyzers/tests/SonarAnalyzer.Test/TestCases/UseAwaitableMethod_MongoDBDriver.cs Lines 12 to 21 in 8b6f0f5
In Mongo DB FindSync is the synchronous version of FindAsync while Find is meant for something else. Because FindAsync and Find only differ in their return type, overload resolution is successful. However, because the return types are not compatible, the overload should be rejected by our logic. I marked this as a false positive and put it in our backlog. |
We have two options on how to solve this
Option 2) can be done easily once #9318 is merged. |
Description
S6966 is being triggered on methods that do not match in method signature. For example, in the MongoDB driver,
Find
andFindAsync
are not related.Find
returnsIFindFluent
for building chained mongo requests, whileFindAsync
returnsIAsyncCursor
. The following should not be triggering S6966.UnrelatedThing Find(string s, int i = 0)
orUnrelatedThing Find(string s)
Task<string> FindAsync(string s)
Only
string Find(string s)
should trigger this rule.Repro steps
Expected behavior
_ = Find("123");
should not trigger S6966.Actual behavior
_ = Find("123");
triggers S6966.Known workarounds
Please provide a description of any known workarounds.
Related information
The text was updated successfully, but these errors were encountered: