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

Cast operation fails when an enum is mapped as an AnsiString #2499

Merged
merged 9 commits into from
Aug 30, 2020

Conversation

gliljas
Copy link
Member

@gliljas gliljas commented Aug 26, 2020

Regression from #2036

Worked fine for enums mapped as String, but not if an AnsiString or FixedLength type was used.

@gliljas gliljas requested a review from maca88 August 26, 2020 16:16
@bahusoid

This comment has been minimized.

@hazzik hazzik force-pushed the ansistringenumcasting branch from d825ec0 to c0bf3c6 Compare August 26, 2020 21:47
@hazzik hazzik changed the base branch from master to 5.3.x August 26, 2020 21:47
hazzik
hazzik previously approved these changes Aug 26, 2020
@hazzik

This comment has been minimized.

Copy link
Member

@bahusoid bahusoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed tests on some dialects...

@gliljas
Copy link
Member Author

gliljas commented Aug 27, 2020

Checking.

@gliljas
Copy link
Member Author

gliljas commented Aug 27, 2020

I will make the "complex" test a bit more legible and predictable.

@bahusoid bahusoid added this to the 5.3.3 milestone Aug 27, 2020
@gliljas
Copy link
Member Author

gliljas commented Aug 27, 2020

I was unable to run the async generator. Never happened before. So I did the asyncification manually...

[exec] Generating async code started [exec] Opening project 'c:\Projects\github\nhibernate-core\src\NHibernate\NHibernate.csproj' started [exec] System.InvalidOperationException: One or more errors occurred while opening the project: [exec] Msbuild failed when processing the file 'c:\Projects\github\nhibernate-core\src\NHibernate\NHibernate.csproj' with message: C:\Program Files\dotnet\sdk\3.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets: (241, 5): The "ResolvePackageAssets" task failed unexpectedly. [exec] System.IO.FileNotFoundException: Could not load file or assembly 'NuGet.ProjectModel, Version=5.7.0.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. [exec] File name: 'NuGet.ProjectModel, Version=5.7.0.7, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ---> System.IO.FileNotFoundException: Could not load the specified file.

@gliljas
Copy link
Member Author

gliljas commented Aug 27, 2020

I believe that the failing query may actually have failed before too, but it surfaced now. Will try to investigate with Firebird or SQLite.

@fredericDelaporte
Copy link
Member

For the async generator, there is an issue with it depending on which Core SDK you have on your setup. There is a workaround here.

@bahusoid
Copy link
Member

bahusoid commented Aug 28, 2020

I believe that the failing query may actually have failed before too, but it surfaced now.

I believe you just changed logic a bit when did conversion to use EnumEntity. Few things I noticed at quick glance:

  1. In original tests special type is used EnumStoredAsStringType with some additional logic (such as Unspecified enum value is set as NULL parameter)
  2. User.NullableEnum1 property is mapped as formula

P.S. I don't think changes you did in last commit are required and I would prefer to keep your initial version - with minimal modifications to original tests.

@gliljas
Copy link
Member Author

gliljas commented Aug 28, 2020

I believe that the failing query may actually have failed before too, but it surfaced now.

I believe you just changed logic a bit when did conversion to use EnumEntity. Few things I noticed at quick glance:

  1. In original tests special type is used EnumStoredAsStringType with some additional logic (such as Unspecified enum value is set as NULL parameter)
  2. User.NullableEnum1 property is mapped as formula

Good catch! I didn't see that hidden complexity.

P.S. I don't think changes you did in last commit are required and I would prefer to keep your initial version - with minimal modifications to original tests.

I mostly agree, although I think a test that checks for count=0 easily hides problems. I'll revert a bit, and probably replicate the EnumStoredAsStringType "features".

This reverts commit b82d1e1.
@bahusoid
Copy link
Member

I just checked generated SQL for SQLite and I think this test indeed reveals new issue (at least for SQLite dialect). I see unnecessary cast in generated SQL. Though I'm pretty sure this issue is unrelated to fix made in this PR:

 select
        enumtests_0_.Id as col_0_0_,
        enumtests_0_.Enum as col_1_0_,
        case 
            when enumtests_0_.Enum=@p0 then 1 
            else 0 
        end as col_2_0_,
        enumtests_0_.Enum as col_3_0_,
        (case 
            when enumtests_0_.Enum = 'Unspecified' then null 
            else enumtests_0_.Enum 
        end) as col_4_0_,
        enumtests_0_.Id as id1_0_,
        enumtests_0_.Name as name2_0_,
        enumtests_0_.Enum as enum3_0_,
        enumtests_0_.Other as other4_0_,
        (case 
            when enumtests_0_.Enum = 'Unspecified' then null 
            else enumtests_0_.Enum 
        end) as formula2_ 
    from
        EnumEntity enumtests_0_ 
    where
        cast(case 
            when (case 
                when enumtests_0_.Enum = 'Unspecified' then null 
                else enumtests_0_.Enum 
            end)=@p1 then @p2 
            else coalesce((case 
                when enumtests_0_.Enum = 'Unspecified' then null 
                else enumtests_0_.Enum 
            end), enumtests_0_.Enum) 
        end as INTEGER)=@p3; -- THIS CAST IS INCORRECT

@maca88 Can you take a look?

@bahusoid bahusoid requested review from hazzik and removed request for hazzik August 28, 2020 14:14
@bahusoid

This comment has been minimized.

@maca88
Copy link
Contributor

maca88 commented Aug 29, 2020

Can you take a look?

I did check it and it is indeed not related to this PR but instead to #707, where transparentcast is added for the ConditionalExpression, which is converted to a cast in SQLite. Prior #707 it would fail for all databases, so it is now minimized to SQLite. Should we fix the issue in this PR or in a separate one?

@bahusoid
Copy link
Member

bahusoid commented Aug 29, 2020

Should we fix the issue in this PR or in a separate one?

I think better to do it in separate PR

@bahusoid bahusoid force-pushed the ansistringenumcasting branch from 5f61374 to 7062def Compare August 29, 2020 16:38
@hazzik
Copy link
Member

hazzik commented Aug 30, 2020

Quick question. What about text, clob, etc?

@maca88
Copy link
Contributor

maca88 commented Aug 30, 2020

I did a quick test by setting the column sql type (m.Column(cm => cm.SqlType("text"))) and it does not work for neither of them.

With clob it fails when inserting rows in the database with error:
System.Data.OracleClient.OracleException : ORA-01722: invalid number

With text the query fails with error:
System.Data.SqlClient.SqlException : The data types text and varchar are incompatible in the equal to operator.

None of the above errors are related to this PR as DbType is still the same, so the casting logic is not affected.

@hazzik
Copy link
Member

hazzik commented Aug 30, 2020

Actually these errors might be because .IsStringType() does not account of these DbTypes.

@hazzik
Copy link
Member

hazzik commented Aug 30, 2020

Ok, checked myself. For StringClobSqlType the DbType is String. So this works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants