question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mixing named and positional parameters isn't supported

See original GitHub issue

Hi,

we are experiencing this issue after upgrading from .NET Core 3.1 to .NET 6 (including the EF Core and Npgsql update, of course). These exceptions are being thrown from multiple queries. I am aware that the exception is thrown from Npgsql driver, but something is probably be wrong here or in EF Core. Unfortunatelly, I am not able to create some unit test or a toy project where I could reproduce it. It happens only in our large project. My guess is that there is either a race somewhere or some parameter objects are being reused and not reinitialized properly. Even in the large project, the same query can be executed fine multiple times and then it fails randomly.

Here is an example from debugger: CommandText = SELECT a.id, a.generations_to_save, a.enabled, a.schedule_json FROM public.auto_backup AS a LIMIT 2 image

On our side, the query is as simple as this (no params):

using var context = _dbScope.CreateNoTrackingDbContext();
var entity = await context.AutoBackup.SingleAsync(cancellationToken);

Another example from the debugger: CommandText = SELECT v.current_usn, v.id FROM ( SELECT public.get_database_id() as id, last_value as current_usn FROM public.server_usn_seq ) AS v LIMIT 2 image

On our side, it is a raw query with no parameters:

const string metadataSql = "SELECT public.get_database_id() as id, last_value as current_usn FROM public.server_usn_seq";
return await context.CreateQuery<DatabaseMetadata>()
                .FromSqlRaw(rawSql)
                .SingleAsync(cancellationToken);

But this happens also to parametrized queries, for example: CommandText =

FROM public.account AS a
WHERE (EXISTS (
    SELECT 1
    FROM public.account_subscription AS a0
    WHERE (a0.subscription_id = @__gSubscriptionId_0) AND (a0.account_id = a.id)) AND ((a.state = 'created'::account_state_enum) AND (a.expiration_date IS NULL OR (a.expiration_date > now())))) AND a.is_deleted_time_utc IS NULL
ORDER BY a.purpose = 'service'::account_purpose_enum DESC
LIMIT 1

image

On our side it looks like this:

var accountIds = context.AccountSubscription
    .Where(connSub => connSub.SubscriptionId == gSubscriptionId)
    .Select(connSub => connSub.AccountId);

query = context.Account
    .OrderByDescending(acc => acc.Purpose == AccountPurpose.Service)
    .Where(acc => accountIds.Contains(acc.Id))
    .Where(acc => acc.State == AzureAccountStateEnum.Created && (acc.ExpirationDate == null || acc.ExpirationDate > DateTime.UtcNow));

query = query.ExcludeDeleted();

var result = await query.FirstOrDefaultAsync(ct);

Could you please help with this issue? It is a show stopper for us when it comes to the upgrade to .NET 6.

Thanks, Martin

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
zitmencommented, Nov 25, 2021

The fix has now been published in the patch CI feed as version 6.0.1-ci.20211125T095229, you can use that until 6.0.1 is released (which should be in a matter of days). It would be great if you could run with that and confirm that the original problem as seen via EF Core no longer occurs.

I confirm it works

1reaction
rojicommented, Nov 25, 2021

And thanks again for the investigation and the fix!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid parameter number: mixed named and positional ...
I have come across this warning I've not seen before: Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid ...
Read more >
Mixing Positional & Named Params Can Lead to Trouble
Mixing positional and named parameters can lead to trouble.
Read more >
Positional and named arguments should not be mixed in ...
... a positional parameter association may not follow a named association exception from being raised, do not mix named and positional argument invocations....
Read more >
Support named arguments in their own position even if the ...
Support named arguments in their own position even if the result appears as mixed.
Read more >
PHP 8.0: Named Parameters
In PHP 8.0, Named Parameters support is added, which means it's now possible to call a function/method by setting the parameters by their...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found