-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PGVector problem #316
Comments
Nothing in the stack trace indicates anything Hangfire-related which makes me think it's XY problem, or that maybe you're using EF drop create database migrations, which in turn doesn't work out too well since the database can get created by this provider first before EF migrations. Can you provide
|
hangfire_startup.txt |
I looked through Hangfire.Postgres source code, but I couldn't find any places that could be potentially causing this issue. PgVector uses Npgsql extensions to add new handlers which allows it to support deserealization of their custom Since all Npgsql extensions are registered on a @MBrekhof can you try the following?
|
Hi, |
Closing the issue as the type mappings are not explicitly changed anywhere in Hangfire.PostgreSql. If trying the suggested changes and/or moving to a separate service doesn't help, you can reopen it. |
It appears that I encountered a similar issue. When I transitioned from using Hangfire's InMemoryStorage to PostgreSQL, I encountered an "invalid cast exception" related to PgVector vector properties. I also attempted @MBrekhof suggestion It seems there is really some conflicting behavior going on CC: @azygis Here is the full stack trace [project-x-api_626157d2-e]: [20:22:55 ERR] An exception occurred in the database while saving changes for context type 'Infrastructure.Data.ApplicationDbContext'. |
Can't see how it's for sure, sorry. This package depends on both Npgsql and Dapper which have their own intristicts about mapping. We do nothing with geometry or special type mappings, at all. It's all happening on Npgsql side. There is a discussion in a linked issue #322 which shows how we can workaround the problem in the last messages, but that has not been done yet and I have no time for it currently. There's also another workaround mentioned, maybe you can try that as well to some extent. |
I have an Blazor Web app that uses EF Core 7 with Postgresql 15 and the PGVector extension installed (https://github.com/pgvector/pgvector). This all works great using ' options.UseNpgsql(connectionString, o => o.UseVector()).UseLowerCaseNamingConvention();' to configure my DBContext.
However as soon as I add Hangfire using:
services.AddHangfire(config => config.UsePostgreSqlStorage(hfconnectionString));
services.AddHangfireServer();
I get this error:
23:04:17:442 SELECT c.codeobjectid, c.codeobjectcategoryid, c.codeobjectcontent, c.subject, c.tokens, c.vectordatastring, c0.codeobjectcategoryid, c0.category
23:04:17:442 FROM codeobject AS c
23:04:17:442 INNER JOIN codeobjectcategory AS c0 ON c.codeobjectcategoryid = c0.codeobjectcategoryid
23:04:17:694 Exception thrown: 'System.InvalidCastException' in Npgsql.dll
23:04:17:694 Exception thrown: 'System.InvalidCastException' in Npgsql.dll
23:04:17:694 Microsoft.EntityFrameworkCore.Query: Error: An exception occurred while iterating over the results of a query for context type 'DocGPT.Module.BusinessObjects.DocGPTEFCoreDbContext'.
23:04:17:694 System.InvalidCastException: Can't cast database type . to Vector
23:04:17:694 at Npgsql.Internal.TypeHandling.NpgsqlTypeHandler.ReadCustom[TAny](NpgsqlReadBuffer buf, Int32 len, Boolean async, FieldDescription fieldDescription)
23:04:17:694 at Npgsql.NpgsqlDataReader.GetFieldValue[T](Int32 ordinal)
23:04:17:694 at lambda_method628(Closure, QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator)
23:04:17:694 at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable
1.Enumerator.MoveNext() 23:04:17:694 23:04:17:694 System.InvalidCastException: Can't cast database type .<unknown> to Vector 23:04:17:694 at Npgsql.Internal.TypeHandling.NpgsqlTypeHandler.ReadCustom[TAny](NpgsqlReadBuffer buf, Int32 len, Boolean async, FieldDescription fieldDescription) 23:04:17:694 at Npgsql.NpgsqlDataReader.GetFieldValue[T](Int32 ordinal) 23:04:17:694 at lambda_method628(Closure, QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator) 23:04:17:694 at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable
1.Enumerator.MoveNext()23:04:17:945 Exception thrown: 'System.InvalidCastException' in Microsoft.EntityFrameworkCore.Relational.dll
23:04:17:945 Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: Can't cast database type . to Vector
23:04:17:945
23:04:17:945 System.InvalidCastException: Can't cast database type . to Vector
23:04:17:945 at Npgsql.Internal.TypeHandling.NpgsqlTypeHandler.ReadCustom[TAny](NpgsqlReadBuffer buf, Int32 len, Boolean async, FieldDescription fieldDescription)
23:04:17:945 at Npgsql.NpgsqlDataReader.GetFieldValue[T](Int32 ordinal)
23:04:17:945 at lambda_method628(Closure, QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator)
23:04:17:945 at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable
1.Enumerator.MoveNext() 23:04:17:945 at DevExpress.EntityFrameworkCore.Security.Query.EnumerableDecorator
1.EnumeratorDecorator.MoveNext()23:04:17:945 at System.Linq.Enumerable.OfTypeIterator[TResult](IEnumerable source)+MoveNext()
23:04:17:945 at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
23:04:17:945 at DevExpress.ExpressApp.EFCore.EFCoreCollection.Init()
23:04:17:945 at DevExpress.ExpressApp.EFCore.EFCoreCollection.get_InnerList()
23:04:17:945 at DevExpress.ExpressApp.EFCore.EFCoreCollection.get_Count()
23:04:17:945 at DevExpress.ExpressApp.ProxyCollection.get_Count()
23:04:17:945 at DevExpress.Data.DataControllerBase.ResetValidateBindingListChangedConsistency(Boolean isSubscribe)
Same query (totaly unrelated to Hangfire) works great when I disable Hangfire and the Hangfire.Postgresql.
Any ideas how to try and solve this?
The text was updated successfully, but these errors were encountered: