Skip to content

Mark AddTypeHandlerImpl as obsolete and prevent lost updates via AddTypeHandler#2129

Merged
mgravell merged 7 commits intomainfrom
nix-impl
Oct 31, 2024
Merged

Mark AddTypeHandlerImpl as obsolete and prevent lost updates via AddTypeHandler#2129
mgravell merged 7 commits intomainfrom
nix-impl

Conversation

@mgravell
Copy link
Copy Markdown
Member

AddTypeHandlerImpl was never intended to be public; oops

also drive-by fix to prevent lost updates via AddTypeHandler

  • mark AddTypeHandlerImpl as obsolete
  • syncronize type-handler mutates, to prevent lost writes

fix #1815

alternate to #2107

- syncronize type-handler mutates, to prevent lost writes
@mgravell
Copy link
Copy Markdown
Member Author

(CI fails: appveyor keep changing the pgsql setup; trying to fix)

Copy link
Copy Markdown
Contributor

@billrob billrob left a comment

Choose a reason for hiding this comment

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

Still not 100% perfect, but 99% on an admin / housekeeping operation will be fine.

@mgravell
Copy link
Copy Markdown
Member Author

Still not 100% perfect, but 99% on an admin / housekeeping operation will be fine.

what concrete scenario are you concerned about?

@mgravell
Copy link
Copy Markdown
Member Author

giving up on fighting appveyor - summoning the one, the only, @NickCraver - any clue? appveyor keep changing the base image; I fixed once here, but can't get to work now

@billrob
Copy link
Copy Markdown
Contributor

billrob commented Oct 31, 2024

Probably more a "not how I would do it" 1%. The iteration when newing the dictionary is still potentially an exception. At least it will throw an exception rather than build a non-desirable dictionary cache. But verily, if someone is running multi-threading add/reset/remove type handlers we could just tell them to not do it.

I don't see that currently possible with the current code base, but more future proofing, because in 2 years will we remember this discussion? lol

@mgravell
Copy link
Copy Markdown
Member Author

The iteration when newing the dictionary is still potentially an exception.

I don't see how:

  1. we never mutate the dictionary once assigned, except for in the .cctor (that's what clone controls)
  2. it doesn't matter because of 1, but we're inside the lock for this iterator, so we know nobody is doing anything except reading

So : in what scenario can we compete? Happy to consider a concrete scenario, but : I don't see it currently.

As for the 2 years thing: we might not remember this specific discussion in the future, but yes: we will know that this is static state that needs concurrency consideration.

@billrob
Copy link
Copy Markdown
Contributor

billrob commented Oct 31, 2024

Any potential issues does not exist currently in the code base and this PR is threaded sound. I'm confident this currently fixes the known threading issues and you should push it. (appveyor issues aside)

Larger story here, I want Dapper to survive EF consuming this project as they often consume popular projects. Should we consider a .UseDapper(with type handler registration) that can internally register this static dictionary as a singleton with DI? That would eliminate all these redo scenarios we potentially could face in the future and fit more inline with .net core direction.

@mgravell
Copy link
Copy Markdown
Member Author

I'm not sure that's the best option for configuration in this case. Over in the AOT side, we allow declarative and contextual configuration via attributes, which allows config to be as granular or global as desired without the need for additional registration or service tracking.

@mgravell mgravell merged commit 9f4f783 into main Oct 31, 2024
@billrob
Copy link
Copy Markdown
Contributor

billrob commented Oct 31, 2024

I had a hard time doing static typemap configuration as Dapper and .net evolved regarding testing. AOT might be a great solution, but it is so far from on-the-ground developers just wanting things to work.

The dotnet .UseXXX has taken off. Dapper is infinitely more configurable than the current EF implementation mimicking Dapper's performance. I might be myopic here, but why shouldn't we want a startup configuration that handles application specific type mappings because almost all scenarios don't involve changing type map configurations while your application is running.

@mgravell mgravell deleted the nix-impl branch October 31, 2024 07:48
@mgravell
Copy link
Copy Markdown
Member Author

Because you can already do that today without requiring a new API. Service registration kinda needs a service state to be "proper" (not just static state), and the existing Dapper bits lack that. As for AOT: you don't need to be deploying via AOT for Dapper's AOT bits to be useful - the aim there is to remove all the reflection code from the critical path.

@NickCraver
Copy link
Copy Markdown
Member

Postgres fixed up in #2130 - the docs are just totally missing past Postgresql 13, so you're not crazy. Even more reason we need to get off AppVeyor.

sloweyyy added a commit to sloweyyy/cloud-native-ecommerce-platform that referenced this pull request Mar 22, 2026
Updated [Dapper](https://github.com/DapperLib/Dapper) from 2.1.35 to
2.1.66.

<details>
<summary>Release notes</summary>

_Sourced from [Dapper's
releases](https://github.com/DapperLib/Dapper/releases)._

## 2.1.66

WARNING: `DateOnly` / `TimeOnly` support, added in 2.1.37, had multiple
failure modes, and was quickly reverted pending finding the time to
investigate what went wrong. The impacted packages were unlisted, with
2.1.35 being the last listed version. This is the first version *after*
that debacle, which means if you are using the impacted 2.1.37 or
similar: this version will effectively *remove* functionality (although
it was actually disabled a very long time ago).

---

## What's Changed
* TFM update; +net8 (LTS), -net5, -net7 by @​mgravell in
DapperLib/Dapper#2144
* normalize async API surface over all TFMs by @​mgravell in
DapperLib/Dapper#2144
* disable DateOnly / TimeOnly support by @​mgravell in
DapperLib/Dapper#2080
* change dapper-plus citation by @​mgravell in
DapperLib/Dapper#2083
* Do not close the inner reader when disposing wrapped data readers by
@​0xced in DapperLib/Dapper#2100
* CI - update pgsql to 13 by @​mgravell in
DapperLib/Dapper#2119
* Fix #​2113 by @​goerch in
DapperLib/Dapper#2118
* update package refs and fixup by @​mgravell in
DapperLib/Dapper#2120
* add mention of MariaDB to Readme.md by @​robertsilen in
DapperLib/Dapper#2116
* Improve performance of "queryunbuffered", and correctness of "first"
APIs by @​mgravell in DapperLib/Dapper#2121
* Properly handle value types when setting properties on dynamic objects
returned by Dapper queries by @​alatanza in
DapperLib/Dapper#2122
* Mark AddTypeHandlerImpl as obsolete and prevent lost updates via
AddTypeHandler by @​mgravell in
DapperLib/Dapper#2129
* Build: Update Postgres script by @​NickCraver in
DapperLib/Dapper#2130

## New Contributors
* @​goerch made their first contribution in
DapperLib/Dapper#2118
* @​robertsilen made their first contribution in
DapperLib/Dapper#2116
* @​alatanza made their first contribution in
DapperLib/Dapper#2122

**Full Changelog**:
DapperLib/Dapper@2.1.44...2.1.66

## 2.1.44

(fixes NuGet readme)

**Full Changelog**:
DapperLib/Dapper@2.1.42...2.1.44

## 2.1.42

## What's Changed

* revert #​2050 - see #​2049 for more details by @​mgravell in
DapperLib/Dapper#2070
* new sponsor: Dapper Plus by @​mgravell in
DapperLib/Dapper#2069

**Full Changelog**:
DapperLib/Dapper@2.1.37...2.1.42

## 2.1.37

## What's Changed
* string and byte[] : add UseGetFieldValue by @​mgravell in
DapperLib/Dapper#2050
* implement DateOnly/TimeOnly by @​mgravell in
DapperLib/Dapper#2051


**Full Changelog**:
DapperLib/Dapper@2.1.35...2.1.37

Commits viewable in [compare
view](DapperLib/Dapper@2.1.35...2.1.66).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Dapper&package-manager=nuget&previous-version=2.1.35&new-version=2.1.66)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

> **Note**
> Automatic rebases have been disabled on this pull request as it has
been open for over 30 days.
sloweyyy added a commit to sloweyyy/cloud-native-ecommerce-platform that referenced this pull request Mar 25, 2026
Updated [Dapper](https://github.com/DapperLib/Dapper) from 2.1.35 to
2.1.66.

<details>
<summary>Release notes</summary>

_Sourced from [Dapper's
releases](https://github.com/DapperLib/Dapper/releases)._

## 2.1.66

WARNING: `DateOnly` / `TimeOnly` support, added in 2.1.37, had multiple
failure modes, and was quickly reverted pending finding the time to
investigate what went wrong. The impacted packages were unlisted, with
2.1.35 being the last listed version. This is the first version *after*
that debacle, which means if you are using the impacted 2.1.37 or
similar: this version will effectively *remove* functionality (although
it was actually disabled a very long time ago).

---

## What's Changed
* TFM update; +net8 (LTS), -net5, -net7 by @​mgravell in
DapperLib/Dapper#2144
* normalize async API surface over all TFMs by @​mgravell in
DapperLib/Dapper#2144
* disable DateOnly / TimeOnly support by @​mgravell in
DapperLib/Dapper#2080
* change dapper-plus citation by @​mgravell in
DapperLib/Dapper#2083
* Do not close the inner reader when disposing wrapped data readers by
@​0xced in DapperLib/Dapper#2100
* CI - update pgsql to 13 by @​mgravell in
DapperLib/Dapper#2119
* Fix #​2113 by @​goerch in
DapperLib/Dapper#2118
* update package refs and fixup by @​mgravell in
DapperLib/Dapper#2120
* add mention of MariaDB to Readme.md by @​robertsilen in
DapperLib/Dapper#2116
* Improve performance of "queryunbuffered", and correctness of "first"
APIs by @​mgravell in DapperLib/Dapper#2121
* Properly handle value types when setting properties on dynamic objects
returned by Dapper queries by @​alatanza in
DapperLib/Dapper#2122
* Mark AddTypeHandlerImpl as obsolete and prevent lost updates via
AddTypeHandler by @​mgravell in
DapperLib/Dapper#2129
* Build: Update Postgres script by @​NickCraver in
DapperLib/Dapper#2130

## New Contributors
* @​goerch made their first contribution in
DapperLib/Dapper#2118
* @​robertsilen made their first contribution in
DapperLib/Dapper#2116
* @​alatanza made their first contribution in
DapperLib/Dapper#2122

**Full Changelog**:
DapperLib/Dapper@2.1.44...2.1.66

## 2.1.44

(fixes NuGet readme)

**Full Changelog**:
DapperLib/Dapper@2.1.42...2.1.44

## 2.1.42

## What's Changed

* revert #​2050 - see #​2049 for more details by @​mgravell in
DapperLib/Dapper#2070
* new sponsor: Dapper Plus by @​mgravell in
DapperLib/Dapper#2069

**Full Changelog**:
DapperLib/Dapper@2.1.37...2.1.42

## 2.1.37

## What's Changed
* string and byte[] : add UseGetFieldValue by @​mgravell in
DapperLib/Dapper#2050
* implement DateOnly/TimeOnly by @​mgravell in
DapperLib/Dapper#2051


**Full Changelog**:
DapperLib/Dapper@2.1.35...2.1.37

Commits viewable in [compare
view](DapperLib/Dapper@2.1.35...2.1.66).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Dapper&package-manager=nuget&previous-version=2.1.35&new-version=2.1.66)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

> **Note**
> Automatic rebases have been disabled on this pull request as it has
been open for over 30 days.
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.

SqlMapper.AddTypeHandler not thread safe

3 participants