-
Notifications
You must be signed in to change notification settings - Fork 71
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
Make optional parameters required #348
Conversation
@cmeeren thanks for giving it a shot, there are few things that needs to be updated before I can merge this: docs/content the documentation may stipulate that omitting the optional parameters is not an option,
The tests also probably needs updating, I'm seeing calls to Execute that don't give the extra parameters, for example:
Can you add those changes to your PR? |
How's that? :) |
@cmeeren thanks a bunch! going to fetch this and get it merged, I think over the weekend. |
Perfect! Looking forward to the release. |
I've fixed compilation of few more tests, but there is one which is concerning myself: CREATE PROCEDURE dbo.Echo(@in SQL_VARIANT = 'Empty')
AS
SELECT @in;
GO [<Fact>]
let SpWithParamOfRefTypeWithNullDefault() =
use echo = new AdventureWorks.dbo.Echo()
Assert.Equal( Some (Some (box "Empty")), echo.ExecuteSingle(None))
Assert.Equal( Some(Some (box 42)), echo.ExecuteSingle 42)
use echoText = new AdventureWorks.dbo.EchoText()
Assert.Equal<string[]>([| "<NULL>" |], echoText.Execute(null) |> Seq.toArray)
let param = "Hello, world!"
Assert.Equal<string[]>([| param |], echoText.Execute( param) |> Seq.toArray) Message:
Assert.Equal() Failure
Expected: Some(Some(Empty))
Actual: Some(null)
Stack Trace:
at ProgrammabilityTest.SpWithParamOfRefTypeWithNullDefault() in ProgrammabilityTests.fs line: 162 I believe this goes beyond a "fix calling code by adding None" breaking change, albeit we are dealing with passing I'd like to get feedback, but I believe this could be a deal breaker for users relying on such. |
Dagnabbit. I have never heart of |
I have an idea and would like to move this forward, if possible. As I understand it, the problem is that when calling an sproc that has a parameter ( Is the above assessment correct? Now, for the possible solution. As mentioned above, I see that we are conflating nullability with default values (e.g. truly optional parameters). My idea is that we can check whether the default value is Does that make sense?
|
Follow-up to my last question above: I see that the if p.DefaultValue.IsNone then
ProvidedParameter(parameterName, parameterType = typedefof<_ option>.MakeGenericType( p.TypeInfo.ClrType))
else
ProvidedParameter(parameterName, parameterType = typedefof<_ option>.MakeGenericType( p.TypeInfo.ClrType) , optionalValue = null) I have added a commit to the PR to show what I mean. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The build succeeds and I'm happy with the current state of this PR. Please let me know if there is anything else you want changed. |
@smoothdeveloper Is this ready to merge, or is there anything you want changed in this PR? |
@cmeeren, I haven't had a chance to take another look (since clearing the compile error in unit test project). I see in the original issue that few users seems to be ok with breaking changes (thumbs up on comment about it) so I'll allocate some time to review and merge this PR. Thanks for contributing it and keeping pushing on it. |
Thanks a lot! Looking forward to this. Time and again I keep getting bitten by this because after adding new parameters to sprocs, I forget to add new parameters when calling them, causing bad/missing data in DB... My fault of course, but this PR would fix that for good 😁 Don't hesitate to let me know if you need anything more here. |
Closed by #400 |
Fixes #327
Untested.