{"action":"created","issue":{"url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/438","repository_url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL","labels_url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/438/labels{/name}","comments_url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/438/comments","events_url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/438/events","html_url":"https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/438","id":327734150,"node_id":"MDU6SXNzdWUzMjc3MzQxNTA=","number":438,"title":"\"InvalidOperationException: No row is available\" in NpgsqlDefaultDataReader using LazyLoader","user":{"login":"takerukoushirou","id":371735,"node_id":"MDQ6VXNlcjM3MTczNQ==","avatar_url":"https://avatars3.githubusercontent.com/u/371735?v=4","gravatar_id":"","url":"https://api.github.com/users/takerukoushirou","html_url":"https://github.com/takerukoushirou","followers_url":"https://api.github.com/users/takerukoushirou/followers","following_url":"https://api.github.com/users/takerukoushirou/following{/other_user}","gists_url":"https://api.github.com/users/takerukoushirou/gists{/gist_id}","starred_url":"https://api.github.com/users/takerukoushirou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takerukoushirou/subscriptions","organizations_url":"https://api.github.com/users/takerukoushirou/orgs","repos_url":"https://api.github.com/users/takerukoushirou/repos","events_url":"https://api.github.com/users/takerukoushirou/events{/privacy}","received_events_url":"https://api.github.com/users/takerukoushirou/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-30T13:36:02Z","updated_at":"2018-05-31T13:31:34Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Since build 2.1.0-rtm-ci.305 lazy loading a one-to-many entity collection fails with the following exception:\r\n\r\n```\r\nInvalidOperationException: No row is available\r\nNpgsql.NpgsqlDefaultDataReader.GetFieldValue<T>(int column) in C:\\projects\\npgsql\\src\\Npgsql\\NpgsqlDefaultDataReader.cs, line 136\r\n\r\nStack\r\nInvalidOperationException: No row is available\r\nNpgsql.NpgsqlDefaultDataReader.GetFieldValue<T>(int column) in C:\\projects\\npgsql\\src\\Npgsql\\NpgsqlDefaultDataReader.cs\r\nlambda_method(Closure , DbDataReader )\r\nMicrosoft.EntityFrameworkCore.Storage.Internal.TypedRelationalValueBufferFactory.Create(DbDataReader dataReader)\r\nMicrosoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable<T>+Enumerator.BufferlessMoveNext(DbContext _, bool buffer)\r\nMicrosoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation<TState, TResult>(Func<DbContext, TState, TResult> operation, Func<DbContext, TState, ExecutionResult<TResult>> verifySucceeded, TState state)\r\nMicrosoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable<T>+Enumerator.MoveNext()\r\nMicrosoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider._TrackEntities<TOut, TIn>(IEnumerable<TOut> results, QueryContext queryContext, IList<EntityTrackingInfo> entityTrackingInfos, IList<Func<TIn, object>> entityAccessors)+MoveNext()\r\nMicrosoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider+ExceptionInterceptor<T>+EnumeratorExceptionInterceptor.MoveNext()\r\nMicrosoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.Load<TSource>(IQueryable<TSource> source)\r\nMicrosoft.EntityFrameworkCore.Internal.EntityFinder<TEntity>.Load(INavigation navigation, InternalEntityEntry entry)\r\nMicrosoft.EntityFrameworkCore.Internal.LazyLoader.Load(object entity, string navigationName)\r\nMicrosoft.EntityFrameworkCore.Infrastructure.LazyLoaderExtensions.Load<TRelated>(ILazyLoader loader, object entity, ref TRelated navigationField, string navigationName)\r\n[...].Article.get_Statistics() in Article.cs\r\n            get => _statistics ?? LazyLoader?.Load(this, ref _statistics);\r\n```\r\n\r\nBuild 2.1.0-rtm-ci.304 works fine without any issues. Since dependencies on Npgsql and EFCore are unchanged between the two builds, this seems to have been introduced with changes between the two builds.\r\n\r\nI'm using a simple lazy loader configuration in `Article.cs`:\r\n```cs\r\n        public virtual ICollection<ArticleStatistic> Statistics\r\n        {\r\n            get => _statistics ?? LazyLoader?.Load(this, ref _statistics);\r\n            set => _statistics = value;\r\n        }\r\n\r\n        private ICollection<ArticleStatistic> _statistics;\r\n\r\n        #region Lazy Loader\r\n\r\n        private ILazyLoader LazyLoader { get; set; }\r\n\r\n        public Article()\r\n        {\r\n        }\r\n\r\n        [UsedImplicitly]\r\n        public Article(ILazyLoader lazyLoader)\r\n        {\r\n            LazyLoader = lazyLoader;\r\n        }\r\n\r\n        #endregion\r\n```\r\n\r\nThe relationship is not further described with the fluent API, using a standard one-to-many relationship as can be seen in the model snapshot:\r\n```cs\r\n            modelBuilder.Entity(\r\n                \"[...].ArticleStatistic\", b => {\r\n                    b.HasOne(\"[...].Article\", \"Entity\")\r\n                     .WithMany(\"Statistics\")\r\n                     .HasForeignKey(\"EntityId\")\r\n                     .OnDelete(DeleteBehavior.Cascade);\r\n                });\r\n```"},"comment":{"url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/comments/393530788","html_url":"https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/438#issuecomment-393530788","issue_url":"https://api.github.com/repos/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/438","id":393530788,"node_id":"MDEyOklzc3VlQ29tbWVudDM5MzUzMDc4OA==","user":{"login":"takerukoushirou","id":371735,"node_id":"MDQ6VXNlcjM3MTczNQ==","avatar_url":"https://avatars3.githubusercontent.com/u/371735?v=4","gravatar_id":"","url":"https://api.github.com/users/takerukoushirou","html_url":"https://github.com/takerukoushirou","followers_url":"https://api.github.com/users/takerukoushirou/followers","following_url":"https://api.github.com/users/takerukoushirou/following{/other_user}","gists_url":"https://api.github.com/users/takerukoushirou/gists{/gist_id}","starred_url":"https://api.github.com/users/takerukoushirou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takerukoushirou/subscriptions","organizations_url":"https://api.github.com/users/takerukoushirou/orgs","repos_url":"https://api.github.com/users/takerukoushirou/repos","events_url":"https://api.github.com/users/takerukoushirou/events{/privacy}","received_events_url":"https://api.github.com/users/takerukoushirou/received_events","type":"User","site_admin":false},"created_at":"2018-05-31T13:31:34Z","updated_at":"2018-05-31T13:31:34Z","author_association":"CONTRIBUTOR","body":"With release version 2.1, the exception has changed as follows:\r\n\r\n```\r\nOverflowException: Numeric value does not fit in a System.Decimal\r\nNpgsql.NpgsqlDefaultDataReader.GetFieldValue<T>(int column) in C:\\projects\\npgsql\\src\\Npgsql\\NpgsqlDefaultDataReader.cs, line 159\r\n\r\nStack\r\nOverflowException: Numeric value does not fit in a System.Decimal\r\nNpgsql.NpgsqlDefaultDataReader.GetFieldValue<T>(int column) in C:\\projects\\npgsql\\src\\Npgsql\\NpgsqlDefaultDataReader.cs\r\nlambda_method(Closure , DbDataReader )\r\nMicrosoft.EntityFrameworkCore.Storage.Internal.TypedRelationalValueBufferFactory.Create(DbDataReader dataReader)\r\nMicrosoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable<T>+Enumerator.BufferlessMoveNext(DbContext _, bool buffer)\r\nMicrosoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation<TState, TResult>(Func<DbContext, TState, TResult> operation, Func<DbContext, TState, ExecutionResult<TResult>> verifySucceeded, TState state)\r\nMicrosoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable<T>+Enumerator.MoveNext()\r\nMicrosoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider._TrackEntities<TOut, TIn>(IEnumerable<TOut> results, QueryContext queryContext, IList<EntityTrackingInfo> entityTrackingInfos, IList<Func<TIn, object>> entityAccessors)+MoveNext()\r\nMicrosoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider+ExceptionInterceptor<T>+EnumeratorExceptionInterceptor.MoveNext()\r\nMicrosoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.Load<TSource>(IQueryable<TSource> source)\r\nMicrosoft.EntityFrameworkCore.Internal.EntityFinder<TEntity>.Load(INavigation navigation, InternalEntityEntry entry)\r\nMicrosoft.EntityFrameworkCore.Internal.LazyLoader.Load(object entity, string navigationName)\r\nMicrosoft.EntityFrameworkCore.Infrastructure.LazyLoaderExtensions.Load<TRelated>(ILazyLoader loader, object entity, ref TRelated navigationField, string navigationName)\r\n[...].Article.get_Statistics() in Article.cs\r\n```\r\n\r\nThe statistics class has a decimal property:\r\n```cs\r\npublic decimal Value { get; set; }\r\n```\r\nwhich is translated as follows in the migrations snapshot:\r\n```cs\r\n            modelBuilder.Entity(\r\n                \"[...].ArticleStatistic\", b => {\r\n                    b.Property<int>(\"Id\")\r\n                     .ValueGeneratedOnAdd()\r\n                     .HasAnnotation(\"Npgsql:ValueGenerationStrategy\", NpgsqlValueGenerationStrategy.SerialColumn);\r\n\r\n                    b.Property<Guid>(\"EntityId\");\r\n[...]\r\n                    b.Property<decimal>(\"Value\");\r\n\r\n                    b.ToTable(\"ArticleStatistics\");\r\n                });\r\n```\r\n\r\nThe table created by PostgreSQL has the following structure:\r\n```sql\r\ncreate table \"ArticleStatistics\"\r\n(\r\n  \"Id\"           serial                   not null\r\n    constraint \"PK_ArticleStatistics\"\r\n    primary key,\r\n[...]\r\n  \"EntityId\"     uuid                     not null\r\n    constraint \"FK_ArticleStatistics_Articles_EntityId\"\r\n    references \"Articles\"\r\n    on delete cascade,\r\n  \"Value\"        numeric                  not null\r\n);\r\n```\r\n\r\nI found one entity where the problem does not show up, and that entity was recently edited. So I tried modifying some statistics and depending on the numeric value, the problem appears or not. In one example the issue appeared due to one value being 22. I changed it to six and the query succeeded, and awkwardly enough changing it back to 22 it still works. Maybe some internal were changed that affect Npgsql and are not visible in the rendered value. Originally this specific value though was an integer that was converted into a .NET decimal before insertion.\r\n\r\nI also checked whether the issue appears if I directly query on the statistics set of the DbContext in a console app, and it does. Thus this issue is not related to lazy loading."}}
{"actor":{"display_login":"takerukoushirou"}}