Gitea: Difference between queryresults in tests and run/debug

Created on 22 Aug 2017  路  4Comments  路  Source: go-gitea/gitea

  • Gitea version (or commit ref): 53e6c94
  • Git version: 2.7.4
  • Operating system: Ubuntu
  • Database (use [x]):

    • [x] PostgreSQL

    • [ ] MySQL

    • [ ] MSSQL

    • [x] SQLite

  • Can you reproduce the bug at https://try.gitea.io:

    • [ ] Yes (provide example URL)

    • [ ] No

    • [x] Not relevant

Description

The query below is working when debugging/running the application with a postgresql database.
But when running make test, thus using an inmemory sqlite database, the query always returns nothing, despite an existing HookTask from fixture.

tasks := make([]*HookTask, 0, 10)
err := x.Where("is_delivered=?", false).Find(&tasks)
if err != nil {
    log.Error(4, "DeliverHooks: %v", err)
}

To check I ran following query in a testcase and the results are now correct.

tasks := make([]*HookTask, 0, 10)
err := x.Where("is_delivered IS NOT", true).Find(&tasks)
if err != nil {
    log.Error(4, "DeliverHooks: %v", err)
}

How could it be that they are different? The same phenomena occurs when querying for users and filter by prohibit_login = false.
IMO this means that test cases aren't reliable.

kinquestion kintesting

All 4 comments

if is_delivered IS NULL, then is_delivered=false is false but is_delivered IS NOT true is true. That's caused by upgraded when add a new column and didn't update all the old records value.

Of course it is obvious that they are differnt. But they event act different in go run vs go test, because one is using sqlite and the other postgresql in my case.

Problem with that is that they are treated differently for each database. At least they were in my tests.

So I propose to add NOT NULL DEFAULT x to all booleans.

I agree that booleans fields should be set as not null default true/false (depending on default)

Closed in favour to a direct proposal #2632

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

jakimfett picture jakimfett  路  3Comments

thehowl picture thehowl  路  3Comments

tuxfanou picture tuxfanou  路  3Comments

Fastidious picture Fastidious  路  3Comments