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

Fix rowversion null behaviour #998

Merged
merged 3 commits into from
Apr 14, 2021
Merged

Conversation

Wraith2
Copy link
Contributor

@Wraith2 Wraith2 commented Mar 19, 2021

Fixes #255

Changed RowVersion/Timestamp null behaviour for SqlDataReader so that it returns a DBNull value instead of an empty byte[]. An AppContext switch has been added to allow reverting to the previous (broken but kept that way for compatibility) behaviour, it's called Switch.Microsoft.Data.SqlClient.LegacyRowVersionNullBehaviour and is cached on first check for the entire process.

N.B. this is a breaking behavioural change.

/cc @dbrownems @bdebaere @mburbea

@cheenamalhotra cheenamalhotra added the 🔨 Breaking Change Use this label for breaking API changes in the driver. label Mar 19, 2021
Copy link
Contributor

@David-Engel David-Engel left a comment

Choose a reason for hiding this comment

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

LGTM

@ErikEJ
Copy link
Contributor

ErikEJ commented Mar 27, 2021

No tests??

@Wraith2
Copy link
Contributor Author

Wraith2 commented Mar 27, 2021

No tests??

The appcontext switch is process global so I couldn't deterministically make sure that it turned on and off for the right tests. It's also a trivial change tested locally so it didn't seem worth doing lots of private reflection.

@roji
Copy link
Member

roji commented Mar 27, 2021

The appcontext switch is process global so I couldn't deterministically make sure that it turned on and off for the right tests. It's also a trivial change tested locally so it didn't seem worth doing lots of private reflection.

I think it should be possible to turn on an appcontext switch as part of the test (i.e. AppContext.SetSwitch), and back off at the end of it; take care to also disable parallelization for that test to avoid affecting other tests running in parallel.

(no idea on whether testing is important for this particular case etc.)

@ErikEJ
Copy link
Contributor

ErikEJ commented Mar 27, 2021

But it should be possible to add a test to confirm the new changed default behaviour? Or do I misunderstand?

@Wraith2
Copy link
Contributor Author

Wraith2 commented Mar 27, 2021

If I can find how to prevent the tests running in parallel as @roji says is possible then yes it can be tested.
I just hoped I could get away without having to write one for something this trivial, I really hate writing tests.

@ErikEJ
Copy link
Contributor

ErikEJ commented Mar 27, 2021

It should be possible to write a test confirming the new behaviour without changing any AppContext switches etc...

@Wraith2
Copy link
Contributor Author

Wraith2 commented Mar 28, 2021

Positive test added.

@cheenamalhotra
Copy link
Member

cheenamalhotra commented Mar 29, 2021

If I can find how to prevent the tests running in parallel as @roji says is possible then yes it can be tested.

@Wraith2
Our tests don't run in parallel in single process.
We run multiple processes for different configurations only.

We also change AppContext switch in other tests to validate behavior before and after, would recommend the same here.

@Wraith2
Copy link
Contributor Author

Wraith2 commented Mar 29, 2021

Should I take that to mean that you wan me to add a negative test?

@Wraith2
Copy link
Contributor Author

Wraith2 commented Apr 3, 2021

Negative test added and positive test reworked to use the same way of ensuring that the test has the correct app context value set. I've used private reflection to set the internal field value and then restore it after each test, without doing this the per-process cache will prevent both tests succeeding in the same process. A simple lock prevents them running concurrently which is safe because they're very fast tests.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 Breaking Change Use this label for breaking API changes in the driver. 🆕 Public API Use this label for new API additions to the driver.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SqlDataReader incorrectly returns null ROWVERSION as an empty byte[]
5 participants