deislabs / hippo

The WebAssembly Platform

Home Page:https://docs.hippofactory.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't create App with PostgreSQL

FrankYang0529 opened this issue · comments

I tried to run spin deploy on following versions, but both of them will get an error message from Hippo.

  • spin 0.4.0 with Hippo v0.17.0
  • spin 0.5.0 with Hippo v0.19.0
fail: Hippo.Application.Apps.Commands.CreateAppCommand[0]
      Hippo Request: Unhandled Exception for Request CreateAppCommand Hippo.Application.Apps.Commands.CreateAppCommand
      Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
       ---> System.InvalidCastException: Cannot write DateTime with Kind=Local to PostgreSQL type 'timestamp with time zone', only UTC is supported. Note that it's not possible to mix DateTimes with different Kinds in an array/range. See the Npgsql.EnableLegacyTimestampBehavior AppContext switch to enable legacy behavior.
         at Npgsql.Internal.TypeHandlers.DateTimeHandlers.TimestampTzHandler.ValidateAndGetLength(DateTime value, NpgsqlParameter parameter)
         at Npgsql.Internal.TypeHandlers.DateTimeHandlers.TimestampTzHandler.ValidateObjectAndGetLength(Object value, NpgsqlLengthCache& lengthCache, NpgsqlParameter parameter)
         at Npgsql.NpgsqlParameter.ValidateAndGetLength()
         at Npgsql.NpgsqlParameterCollection.ValidateAndBind(ConnectorTypeMapper typeMapper)
         at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
         at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
         at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
         at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
         at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
         at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
         --- End of inner exception stack trace ---

Reproduce steps:

  1. Setup Bindle
BINDLE_TEMP=$(mktemp -d)
bindle-server --unauthenticated -d $BINDLE_TEMP
  1. Setup nomad
nomad agent --dev
  1. Setup PostgreSQL
docker run --name postgres -d --restart=unless-stopped -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=hippo -p 5432:5432 postgres:14
  1. Setup Hippo
export Database__Driver=postgresql
export ConnectionStrings__Database="Host=localhost;Username=postgres;Password=postgres;Database=hippo"
export ConnectionStrings__Bindle="Address=http://127.0.0.1:8080/v1"
export Nomad__Driver="raw_exec"
export Jwt__Key="ceci n'est pas une jeton"
export Jwt__Issuer="localhost"
export Jwt__Audience="localhost"
dotnet build
dotnet run
  1. Create App
export BINDLE_URL="http://localhost:8080/v1/"
export HIPPO_USERNAME="admin"
export HIPPO_PASSWORD="p@ssword"
export HIPPO_URL="http://localhost:5309"

spin new http-rust myapp
cd myapp
spin build
spin deploy

Error: Unable to create Hippo app

Caused by:
    {"type":"https://tools.ietf.org/html/rfc7231#section-6.6.1","title":"An error occurred while processing your request.","status":500,"detail":"DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details."}

@bacongobbler could this be due to needing a specific Postgres version (or subset) for compatibility with hippo?

In .NET, there are two types of DateTime objects:

  • DateTime.Now, which produces local timestamps
  • DateTime.UtcNow, which produces UTC timestamps

Unlike other databases, PostgreSQL represents DateTimes with two different types: one with timezones, and one without.

To address this, Npgsql 6.0 introduced a breaking change forcing users to either use UTC DateTimes everywhere, or revert back to "timestamp without time zone" (i.e. local DateTime objects via DateTime.Now).

Because our intent is to use UTC timestamps, switching out all calls in Hippo from DateTime.Now to DateTime.UtcNow fixes the issue across all database providers.