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.

DateTime.Now.AddDays(-1) throw Npgsql.PostgresException

See original GitHub issue

This always works

DateTime changedAfter = DateTime.Now.AddDays(-1);

await _context.Entity
    .Where(e => e.Updated > changedAfter)
    .ToListAsync();

My understanding is that your translater now translate a specific DateTime, which always works.

This throws exception on a certain environment

Getting an exception on linux docker container (microsoft/dotnet:2.2.2-aspnetcore-runtime) in english/utc timezone with Npgsql.EntityFrameworkCore.PostgreSQL 2.2.0, with Microsoft.AspNetCore.App 2.2.2.

Strangly enough, it dont throw an exception on my development environment which is windows 10, norwegian/utc+2 timezoned. Against the same database with the same runtime version.

await _context.Entity
    .Where(e => e.Updated > DateTime.Now.AddDays(-1))
    .ToListAsync();

My understanding is that now you are translating AddDays(-1), which fails.

Npgsql.PostgresException
22007: invalid input syntax for type interval: "−1 days"

Npgsql.PostgresException (0x80004005): 22007: invalid input syntax for type interval: "−1 days"
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteAsync(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.BufferlessMoveNext(DbContext _, Boolean buffer, CancellationToken cancellationToken)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable`1.AsyncEnumerator.MoveNext(CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.AsyncSelectEnumerable`2.AsyncSelectEnumerator.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator`2.MoveNextCore(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Select.cs:line 106
   at System.Linq.AsyncEnumerable.AsyncIterator`1.MoveNext(CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line 98
   at Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken)
   at System.Linq.AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable`1 source, TAccumulate seed, Func`3 accumulator, Func`2 resultSelector, CancellationToken cancellationToken) in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Aggregate.cs:line 120
   at Dyrket.NotifySubscriptionChangesJob.GetRecentlyChangedSubscriptionsAsync(Int32 forSupplierId) in /app/Dyrket/Jobs/Subscription/NotifySubscriptionChangesJob.cs:line 56
   at Dyrket.NotifySubscriptionChangesJob.RunAsync(IJobCancellationToken cancellationToken) in /app/Dyrket/Jobs/Subscription/NotifySubscriptionChangesJob.cs:line 34

Thanks for an otherwise very stable/reliable implementation of EF Core!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:29 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
smitpatelcommented, Mar 21, 2019

a slightly related thing, the actual character in the source code file may also matter depending on the encoding of the file it is difficult to figure out the difference.

1reaction
rojicommented, Mar 21, 2019

@Andrioden just to be clear, even if the fix we pushed doesn’t address your issue, it’s still important - there are various other culture-related bugs that it prevents.

@austindrenski are you able to continue investigating this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exception when comparing dates - Npgsql. ...
So I'm going to say the field in the database is of varchar not timestamp . If so not a good idea to...
Read more >
Date and Time Handling
NET types and PostgreSQL represent dates. It's worth reading the PostgreSQL date/time type documentation to familiarize yourself with PostgreSQL's types.
Read more >
DateTime.AddDays(Double) Method (System)
Returns a new DateTime that adds the specified number of days to the value of this instance.
Read more >
Untitled
How To Use DAX DATEDIFF In Power BI (2023) Using DateTime. ... DateTime.Now.AddDays(-1) throw Npgsql.PostgresException #847 - GitHub WebMar 15, 2023 · Bus, ......
Read more >
Using DateOnly and TimeOnly in .NET 6 - Steve Gordon
1. var currentDate = DateOnly.FromDateTime(DateTime.Now); ... which may throw an exception or TryParse, which returns a bool indicating ...
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