Skip to content

feat(client): disallow explicit undefined value for adapter - #21315

Merged
millsp merged 2 commits into
mainfrom
feat-client-disallow-explicit-undefined-value-for-adapter
Oct 3, 2023
Merged

millsp merged 2 commits into
mainfrom
feat-client-disallow-explicit-undefined-value-for-adapter

Conversation

@aqrln

@aqrln aqrln commented Oct 2, 2023

Copy link
Copy Markdown
Member

Throw on explicit undefined value of adapter (but not on missing
property) and allow null to conditionally or explicitly disable driver
adapters, as suggested in #21163 (comment).

Closes https://github.com/prisma/team-orm/issues/388

Throw on explicit `undefined` value of `adapter` (but not on missing
property) and allow `null` to conditionally or explicitly disable driver
adapters, as suggested in <#21163 (comment)>.

Closes prisma/team-orm#388
@aqrln
aqrln requested a review from a team as a code owner October 2, 2023 22:47
@aqrln
aqrln requested review from Druue, Jolg42 and millsp and removed request for a team October 2, 2023 22:47
@github-actions

github-actions Bot commented Oct 2, 2023 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
packages/client/runtime/library.d.ts 97.54 KB (0%)
packages/client/runtime/library.js 179.63 KB (+0.07% 🔺)
packages/client/runtime/binary.js 601.57 KB (+0.02% 🔺)
packages/client/runtime/edge.js 209.12 KB (+0.06% 🔺)
packages/cli/build/index.js 5.07 MB (0%)

@aqrln aqrln added this to the 5.4.0 milestone Oct 2, 2023
@millsp
millsp merged commit 00a2fce into main Oct 3, 2023
@millsp
millsp deleted the feat-client-disallow-explicit-undefined-value-for-adapter branch October 3, 2023 00:13
}
if (adapter === undefined) {
throw new PrismaClientConstructorValidationError(
`"adapter" property must not be undefined, use null to conditionally disable driver adapters.`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Additionally, we could also mention: Or remove the driverAdapters preview feature flag?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(though that would not be an option once it's GA)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Without the feature flag though it would be an unknown option.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

at least on the type level

steebchen pushed a commit to prisma-client-go/prisma that referenced this pull request Oct 4, 2023
aqrln added a commit that referenced this pull request Nov 3, 2025
This PR introduces a new way to configure the Accelerate URL in
preparation to removing `url` from PSL:

```ts
new PrismaClient({
  accelerateUrl: "prisma://...",
})
```

This property is mutually exclusive with `adapter`, and exactly one of
them needs to be provided when using `engineType = "client"`.

It also makes a few related changes along the way or as a side effect:

- Contributes towards
[TML-1459](https://linear.app/prisma-company/issue/TML-1459/remove-processenv-loading-from-prisma-cli-and-prismaclient):
the logic related to environment variables was completely removed from
the `RemoteExecutor` code path, along with the `resolveDatasourceUrl`
function.

- Fixes the `@prisma/extension-accelerate` extension which was
inadvertently broken in #28345:
while most of `accelerateUtils` (which were meant to be used by the
removed `AccelerateEngine`) were indeed never used, one specific method
is actually currently used:
`_accelerateEngineConfig.accelerateUtils.resolveDatasourceUrl`. This PR
now restores this function and re-implements it in a different way.
- As a result of this, we now have a new validation and a DX improvement
we didn't use to: now if you apply the Accelerate extension to a client
that's not actually configured to use Accelerate, you will get a very
clear error with a code suggestion.

- Removes `null` support for the `adapter` constructor option, which was
introduced in #21315. It was the
only option that required `null` instead of `undefined` to disable it
explicitly and it was inconsistent with the others. The [motivation for
introducing `null` and making it different from
`undefined`](#21163 (comment))
made total sense for the `LibraryEngine` (where accidentally setting the
`adapter` to `undefined` meant silently using completely different
drivers before that change) but is now obsolete for the `ClientEngine`.
Since we are removing `LibraryEngine` in
#28375, we don't need this
distinction anymore since there are no longer any pitfalls from using
`adapter: undefined`, and removing it here in this PR made the
validation around the combinations of `adapter` and `accelerateUrl`
easier.

- Fixed the incorrect error message when Accelerate URL cannot be
parsed.

Closes:
https://linear.app/prisma-company/issue/TML-1507/env-less-accelerate-url-configuration
aqrln added a commit that referenced this pull request Nov 17, 2025
This PR introduces a new way to configure the Accelerate URL in
preparation to removing `url` from PSL:

```ts
new PrismaClient({
  accelerateUrl: "prisma://...",
})
```

This property is mutually exclusive with `adapter`, and exactly one of
them needs to be provided when using `engineType = "client"`.

It also makes a few related changes along the way or as a side effect:

- Contributes towards
[TML-1459](https://linear.app/prisma-company/issue/TML-1459/remove-processenv-loading-from-prisma-cli-and-prismaclient):
the logic related to environment variables was completely removed from
the `RemoteExecutor` code path, along with the `resolveDatasourceUrl`
function.

- Fixes the `@prisma/extension-accelerate` extension which was
inadvertently broken in #28345:
while most of `accelerateUtils` (which were meant to be used by the
removed `AccelerateEngine`) were indeed never used, one specific method
is actually currently used:
`_accelerateEngineConfig.accelerateUtils.resolveDatasourceUrl`. This PR
now restores this function and re-implements it in a different way.
- As a result of this, we now have a new validation and a DX improvement
we didn't use to: now if you apply the Accelerate extension to a client
that's not actually configured to use Accelerate, you will get a very
clear error with a code suggestion.

- Removes `null` support for the `adapter` constructor option, which was
introduced in #21315. It was the
only option that required `null` instead of `undefined` to disable it
explicitly and it was inconsistent with the others. The [motivation for
introducing `null` and making it different from
`undefined`](#21163 (comment))
made total sense for the `LibraryEngine` (where accidentally setting the
`adapter` to `undefined` meant silently using completely different
drivers before that change) but is now obsolete for the `ClientEngine`.
Since we are removing `LibraryEngine` in
#28375, we don't need this
distinction anymore since there are no longer any pitfalls from using
`adapter: undefined`, and removing it here in this PR made the
validation around the combinations of `adapter` and `accelerateUrl`
easier.

- Fixed the incorrect error message when Accelerate URL cannot be
parsed.

Closes:
https://linear.app/prisma-company/issue/TML-1507/env-less-accelerate-url-configuration
aqrln added a commit that referenced this pull request Nov 17, 2025
This PR introduces a new way to configure the Accelerate URL in
preparation to removing `url` from PSL:

```ts
new PrismaClient({
  accelerateUrl: "prisma://...",
})
```

This property is mutually exclusive with `adapter`, and exactly one of
them needs to be provided when using `engineType = "client"`.

It also makes a few related changes along the way or as a side effect:

- Contributes towards
[TML-1459](https://linear.app/prisma-company/issue/TML-1459/remove-processenv-loading-from-prisma-cli-and-prismaclient):
the logic related to environment variables was completely removed from
the `RemoteExecutor` code path, along with the `resolveDatasourceUrl`
function.

- Fixes the `@prisma/extension-accelerate` extension which was
inadvertently broken in #28345:
while most of `accelerateUtils` (which were meant to be used by the
removed `AccelerateEngine`) were indeed never used, one specific method
is actually currently used:
`_accelerateEngineConfig.accelerateUtils.resolveDatasourceUrl`. This PR
now restores this function and re-implements it in a different way.
- As a result of this, we now have a new validation and a DX improvement
we didn't use to: now if you apply the Accelerate extension to a client
that's not actually configured to use Accelerate, you will get a very
clear error with a code suggestion.

- Removes `null` support for the `adapter` constructor option, which was
introduced in #21315. It was the
only option that required `null` instead of `undefined` to disable it
explicitly and it was inconsistent with the others. The [motivation for
introducing `null` and making it different from
`undefined`](#21163 (comment))
made total sense for the `LibraryEngine` (where accidentally setting the
`adapter` to `undefined` meant silently using completely different
drivers before that change) but is now obsolete for the `ClientEngine`.
Since we are removing `LibraryEngine` in
#28375, we don't need this
distinction anymore since there are no longer any pitfalls from using
`adapter: undefined`, and removing it here in this PR made the
validation around the combinations of `adapter` and `accelerateUrl`
easier.

- Fixed the incorrect error message when Accelerate URL cannot be
parsed.

Closes:
https://linear.app/prisma-company/issue/TML-1507/env-less-accelerate-url-configuration
aqrln added a commit that referenced this pull request Nov 17, 2025
This PR introduces a new way to configure the Accelerate URL in
preparation to removing `url` from PSL:

```ts
new PrismaClient({
  accelerateUrl: "prisma://...",
})
```

This property is mutually exclusive with `adapter`, and exactly one of
them needs to be provided when using `engineType = "client"`.

It also makes a few related changes along the way or as a side effect:

- Contributes towards
[TML-1459](https://linear.app/prisma-company/issue/TML-1459/remove-processenv-loading-from-prisma-cli-and-prismaclient):
the logic related to environment variables was completely removed from
the `RemoteExecutor` code path, along with the `resolveDatasourceUrl`
function.

- Fixes the `@prisma/extension-accelerate` extension which was
inadvertently broken in #28345:
while most of `accelerateUtils` (which were meant to be used by the
removed `AccelerateEngine`) were indeed never used, one specific method
is actually currently used:
`_accelerateEngineConfig.accelerateUtils.resolveDatasourceUrl`. This PR
now restores this function and re-implements it in a different way.
- As a result of this, we now have a new validation and a DX improvement
we didn't use to: now if you apply the Accelerate extension to a client
that's not actually configured to use Accelerate, you will get a very
clear error with a code suggestion.

- Removes `null` support for the `adapter` constructor option, which was
introduced in #21315. It was the
only option that required `null` instead of `undefined` to disable it
explicitly and it was inconsistent with the others. The [motivation for
introducing `null` and making it different from
`undefined`](#21163 (comment))
made total sense for the `LibraryEngine` (where accidentally setting the
`adapter` to `undefined` meant silently using completely different
drivers before that change) but is now obsolete for the `ClientEngine`.
Since we are removing `LibraryEngine` in
#28375, we don't need this
distinction anymore since there are no longer any pitfalls from using
`adapter: undefined`, and removing it here in this PR made the
validation around the combinations of `adapter` and `accelerateUrl`
easier.

- Fixed the incorrect error message when Accelerate URL cannot be
parsed.

Closes:
https://linear.app/prisma-company/issue/TML-1507/env-less-accelerate-url-configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants