Skip to content
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

[BUG] Install with PostgreSQL in Docker error: Object reference not set to an instance of an object at RewriteName(String name) #4770

Closed
pollux opened this issue Oct 23, 2024 · 5 comments

Comments

@pollux
Copy link
Contributor

pollux commented Oct 23, 2024

Oqtane Info

Version - 5.2.4
Render Mode - Static
Interactivity - Server
Database - PostgreSQL

Environment Info

  • Docker: 27.2.0, build 3ab4256
  • Docker compose: v2.29.2-desktop.2
  • Docker Desktop: 4.34.2 (167172)
  • Host: Windows 11 Home

Describe the bug

When installing Oqtane with a PostgreSQL database the installer runs into an error.
When doing the same with a Microsoft SQL Server it works.

Error:
image

Expected Behavior

The Installer not running into an error.

Steps To Reproduce

  1. Spin up an instance through the provided Compose file (the Dockerfile will be built automatically)
  2. Connect to Oqtane via Web Browser, e.g. http://localhost
  3. Fill out the install form
  4. Click "Install"

Anything else?

Dockerfile

# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 80

ENV ASPNETCORE_URLS=http://+:80
ENV ASPNETCORE_HTTP_PORTS=80
ENV ASPNETCORE_ENVIRONMENT=Production

# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Oqtane.Server/Oqtane.Server.csproj", "Oqtane.Server/"]
COPY ["Oqtane.Client/Oqtane.Client.csproj", "Oqtane.Client/"]
COPY ["Oqtane.Shared/Oqtane.Shared.csproj", "Oqtane.Shared/"]
COPY ["Oqtane.Database.MySQL/Oqtane.Database.MySQL.csproj", "Oqtane.Database.MySQL/"]
COPY ["Oqtane.Database.PostgreSQL/Oqtane.Database.PostgreSQL.csproj", "Oqtane.Database.PostgreSQL/"]
COPY ["Oqtane.Database.SqlServer/Oqtane.Database.SqlServer.csproj", "Oqtane.Database.SqlServer/"]
COPY ["Oqtane.Database.Sqlite/Oqtane.Database.Sqlite.csproj", "Oqtane.Database.Sqlite/"]

RUN dotnet restore "Oqtane.Server/Oqtane.Server.csproj"
RUN dotnet restore "Oqtane.Database.SqlServer/Oqtane.Database.SqlServer.csproj"
RUN dotnet restore "Oqtane.Database.PostgreSQL/Oqtane.Database.PostgreSQL.csproj"

COPY . .

RUN dotnet build "Oqtane.Database.MySQL/Oqtane.Database.MySQL.csproj" -c $BUILD_CONFIGURATION -o /app/build/

RUN dotnet build "Oqtane.Database.PostgreSQL/Oqtane.Database.PostgreSQL.csproj" -c $BUILD_CONFIGURATION -o /app/build/

RUN dotnet build "Oqtane.Database.SqlServer/Oqtane.Database.SqlServer.csproj" -c $BUILD_CONFIGURATION -o /app/build/

RUN dotnet build "Oqtane.Database.Sqlite/Oqtane.Database.Sqlite.csproj" -c $BUILD_CONFIGURATION -o /app/build/

WORKDIR "/src/Oqtane.Server"
#RUN dotnet build "Oqtane.Server.csproj" -c $BUILD_CONFIGURATION -o /app/build

# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "Oqtane.Server.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY Oqtane.Server/appsettings.json . 
ENTRYPOINT ["dotnet", "Oqtane.Server.dll"]

Docker Compose - Microsoft SQL Server

name: oqtane

services:
    oqtane.server:
        container_name: oqtane-dev
        restart: unless-stopped
        build: 
          context: .
          dockerfile: Dockerfile
          tags: ["latest","5.2.4"]
        ports:
            - "80:80"
        depends_on:
            - sqldata
        environment:
            - "ASPNETCORE_URLS=http://+:80"
            - "ASPNETCORE_HTTP_PORTS=80"
            - "ASPNETCORE_ENVIRONMENT=Development"
        networks:
            - octane-net
        volumes:
            - "C:/OqtaneVolumes/appsettings.json:/app/appsettings.json:rw"
            - "C:/OqtaneVolumes/Data:/app/Data:rw"
            - "C:/OqtaneVolumes/Content:/app/Content:rw"
            - "C:/OqtaneVolumes/Packages:/app/Packages:rw"
        mem_limit: 1g

    sqldata:
        image: mcr.microsoft.com/mssql/server:2022-latest 
        environment:
            - "SA_PASSWORD=SecureDB2024-"
            - "ACCEPT_EULA=Y"
        networks:
            - octane-net
        volumes:
            - oqtane_db:/var/opt/mssql
        ports:
        - "1533:1433"
volumes:
    oqtane_db:
    oqtane_fs:

networks:
    octane-net:

Docker Compose - PostgreSQL

name: oqtane

services:
    oqtane.server:
        container_name: oqtane-dev
        restart: unless-stopped
        build: 
          context: .
          dockerfile: Dockerfile
          tags: ["latest","5.2.4"]
        ports:
            - "80:80"
        depends_on:
            - postgresql-data
        environment:
            - "ASPNETCORE_URLS=http://+:80"
            - "ASPNETCORE_HTTP_PORTS=80"
            - "ASPNETCORE_ENVIRONMENT=Development"
        networks:
            - octane-net
        volumes:
            - "C:/OqtaneVolumes/appsettings.json:/app/appsettings.json:rw"
            - "C:/OqtaneVolumes/Data:/app/Data:rw"
            - "C:/OqtaneVolumes/Content:/app/Content:rw"
            - "C:/OqtaneVolumes/Packages:/app/Packages:rw"
        mem_limit: 1g

    postgresql-data:
        restart: unless-stopped
        image: postgres:13
        container_name: oqtane-database
        environment:
            - "POSTGRES_PASSWORD=postgres"
            - "POSTGRES_USER=postgres"
            - "PGDATA=/var/lib/postgresql/data"
        networks:
            - octane-net
        volumes:
            - "C:/OqtaneVolumes/postgresdata:/var/lib/postgresql/data:rw"
        ports:
            - "5432:5432"
volumes:
    oqtane_db:
    oqtane_fs:

networks:
    octane-net:
@pollux
Copy link
Contributor Author

pollux commented Oct 23, 2024

FYI: #2091 was used as a basis

@sbwalker
Copy link
Member

Does this error only occur in the Docker configuration, or does it occur in other configurations as well (ie. a basic local installation without Docker)?

@pollux
Copy link
Contributor Author

pollux commented Oct 24, 2024

After running Oqtane through IIS Express in Debug mode, so without docker, the error occurred as well.

@sbwalker
Copy link
Member

sbwalker commented Oct 24, 2024

I see a reference in the error message to AddForeignKey() and there was an enhancement submitted by @Hypnodude in the 5.2.4 release to support PrincipalSchema when creating foreign keys (#4726) - so I am now wondering if this may have caused a regression issue in the PostgreSQL database provider.

@sbwalker
Copy link
Member

sbwalker commented Oct 24, 2024

@pollux I am able to reproduce this problem... and I can confirm that it was caused by PR #4726

BaseEntityBuilder calls:

AddForeignKey(table, foreignKey);

Which calls the following method:

        public void AddForeignKey(CreateTableBuilder<TEntityBuilder> table, ForeignKey<TEntityBuilder> foreignKey)
        {
            table.ForeignKey(
                name: RewriteName(foreignKey.Name),
                column: foreignKey.Column,
                principalTable: RewriteName(foreignKey.PrincipalTable),
                principalColumn: RewriteName(foreignKey.PrincipalColumn),
                principalSchema: RewriteName(foreignKey.PrincipalSchema),
                onDelete: foreignKey.OnDeleteAction);
        }

The foreignKey.PrincipalSchema was added in 5.2.4 and its value is null which causes RewriteName() to throw a null reference exception when installing on PostgreSQL. It does not happen on other databases because they do not have a custom RewriteName() method - only PostgreSQL requires this because of its snake case naming convention for objects.

sbwalker added a commit that referenced this issue Oct 24, 2024
fix #4770 - set a default value for PrincipalSchema to ensure backward compatibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants