Brewtarget / brewtarget

Main brewtarget source code repository.
GNU General Public License v3.0
313 stars 134 forks source link

Postgres issue w/ fresh install #760

Closed marker5a closed 1 year ago

marker5a commented 1 year ago

I setup a fresh postgres14 instance w/ an empty schema and connected a fresh install of brewtarget to the database through the settings page. After connecting successfully and presumably setting up the schema and init data, it prompted me to restart.

After exiting, Brewtarget will no longer startup and it returns the following assertion log:

[13:26:36.135] (1dtmv05kg0) INFO : Starting Brewtarget v 3.0.9 (app name "brewtarget" ) on "Arch Linux" [main.cpp:195] [13:26:36.135] (1dtmv05kg0) INFO : Built at 2023-07-03 16:48:40 (UTC) on Linux-5.15.94-1-lts for Linux-5.15.94-1-lts with GNU compiler [main.cpp:198] [13:26:36.135] (1dtmv05kg0) INFO : Log directory: "/home/marker5a" [main.cpp:201] [13:26:36.135] (1dtmv05kg0) INFO : Using Qt runtime v 5.15.10 (compiled against Qt v 5.15.10 ) [main.cpp:202] [13:26:36.135] (1dtmv05kg0) INFO : Configuration directory: "/home/marker5a/.config/brewtarget" [main.cpp:203] [13:26:36.135] (1dtmv05kg0) INFO : Data directory: "/home/marker5a/.config/brewtarget" [main.cpp:204] [13:26:36.135] (1dtmv05kg0) INFO : void {anonymous}::initResourceDir(QDir&) Determined resource directory is "/usr/share/brewtarget" [Application.cpp:342] [13:26:36.135] (1dtmv05kg0) INFO : Resource directory: "/usr/share/brewtarget" [main.cpp:205] [13:26:37.077] (1dtmv05kg0) INFO : bool Database::load() Known DB drivers: ("QIBASE", "QSQLITE", "QSQLITE3", "QMARIADB", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7", "QTDS", "QTDS7") [database/Database.cpp:638] [13:26:37.109] (1dtmv05kg0) INFO : bool Database::impl::loadPgSQL(Database&) PostgreSQL version QVariant(QString, "PostgreSQL 14.8 (Debian 14.8-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit") [database/Database.cpp:386] [13:26:37.115] (1dtmv05kg0) INFO : bool Database::impl::updateSchema(Database&, bool) Schema version in DB: 10 , current schema version in code: 10 [database/Database.cpp:399] [13:26:37.152] (1dtmv05kg0) ERROR : void ObjectStore::impl::wrapAndUnmapAsNeeded(const ObjectStore::TableDefinition&, const ObjectStore::TableField&, QVariant&) Unexpected type # 2 = int in QVariant for property fermentationStages , field type FieldType # 2 : ( "ObjectStore::FieldType::UInt" ) , value QVariant(int, 1) , table recipe , column fermentation_stages [database/ObjectStore.cpp:699] [13:26:37.154] (1dtmv05kg0) ERROR : void ObjectStore::impl::wrapAndUnmapAsNeeded(const ObjectStore::TableDefinition&, const ObjectStore::TableField&, QVariant&) Call stack is: Stacktrace: 0# Logging::getStackTrace() in brewtarget 1# ObjectStore::impl::wrapAndUnmapAsNeeded(ObjectStore::TableDefinition const&, ObjectStore::TableField const&, QVariant&) in brewtarget 2# ObjectStore::loadAll(Database) in brewtarget 3# 0x00007FD5ECE605BF in /usr/lib/libc.so.6 4# ObjectStoreTyped::getInstance() in brewtarget 5# BtTreeModel::BtTreeModel(BtTreeView, BtTreeModel::TypeMasks) in brewtarget 6# BtTreeView::BtTreeView(QWidget, BtTreeModel::TypeMasks) in brewtarget 7# RecipeTreeView::RecipeTreeView(QWidget) in brewtarget 8# Ui_mainWindow::setupUi(QMainWindow) in brewtarget 9# MainWindow::MainWindow(QWidget*) in brewtarget 10# 0x000056514D45DA3F in brewtarget 11# 0x00007FD5ECE605BF in /usr/lib/libc.so.6 12# MainWindow::instance() in brewtarget 13# Application::run() in brewtarget 14# main in brewtarget 15# 0x00007FD5ECDF7850 in /usr/lib/libc.so.6 16# __libc_start_main in /usr/lib/libc.so.6 17# _start in brewtarget [database/ObjectStore.cpp:704] [13:26:37.154] (1dtmv05kg0) ERROR : ASSERT: "false" in file /media/build_environment/yaourt/yaourt-tmp-marker5a/aur-brewtarget/src/brewtarget-3.0.9/src/database/ObjectStore.cpp, line 706 [database/ObjectStore.cpp:706] Aborted (core dumped)

From looking at the code, it looks to just be a typecast issue... I changed it on my working copy and it seems fine...


diff --git a/src/database/ObjectStoreTyped.cpp b/src/database/ObjectStoreTyped.cpp
index 91093c1f..f9f0e259 100644
--- a/src/database/ObjectStoreTyped.cpp
+++ b/src/database/ObjectStoreTyped.cpp
@@ -563,7 +563,7 @@ namespace {
          {ObjectStore::FieldType::Date,   "date",                PropertyNames::Recipe::date                },
          {ObjectStore::FieldType::Double, "efficiency",          PropertyNames::Recipe::efficiency_pct      },
          {ObjectStore::FieldType::Int,    "equipment_id",        PropertyNames::Recipe::equipmentId,          nullptr,                &PRIMARY_TABLE<Equipment>},
-         {ObjectStore::FieldType::UInt,   "fermentation_stages", PropertyNames::Recipe::fermentationStages  },
+         {ObjectStore::FieldType::Int,   "fermentation_stages", PropertyNames::Recipe::fermentationStages  },
          {ObjectStore::FieldType::Double, "fg",                  PropertyNames::Recipe::fg                  },
          {ObjectStore::FieldType::Bool,   "forced_carb",         PropertyNames::Recipe::forcedCarbonation   },
          {ObjectStore::FieldType::Double, "keg_priming_factor",  PropertyNames::Recipe::kegPrimingFactor    },
matty0ung commented 1 year ago

Ah, good spot, and, yes, that's a good fix. (Alternatively, if we wanted to be super pedantic about the fact that there should never be a negative number of fermentation stages, then, in model/Recipe.h, we could make fermentationStages an unsigned int property, with the corresponding changes to its getter and setter, but I'm not sure if that would be worth the hassle.)

AFAICT this is a property that we don't currently expose in the UI, but I'm hoping/expecting to change that as part of the BeerJSON work.

matty0ung commented 1 year ago

If you want to do a PR, I'll happily approve it.

Otherwise I'll include the fix in whatever the next commit is.

marker5a commented 1 year ago

Ok, cool, I'll do a PR for it momentarily

On Mon, Jul 3, 2023 at 2:30 PM Matt Young @.***> wrote:

If you want to do a PR, I'll happily approve it.

Otherwise I'll include the fix in whatever the next commit is.

— Reply to this email directly, view it on GitHub https://github.com/Brewtarget/brewtarget/issues/760#issuecomment-1618984437, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSNTYIMRW6IHYIVFYSKIPTXOMFWFANCNFSM6AAAAAAZ4YT2RI . You are receiving this because you authored the thread.Message ID: @.***>

matty0ung commented 1 year ago

PS: I do half expect you to find other PostgreSQL issues, because it's a bit less fast-and-loose about things than SQLite. They should all be fixable though!

marker5a commented 1 year ago

Yeah, totally understandable. I'm planning on moving over to postgres for brewtarget, so hopefully I'll uncover the bugs :)

On Mon, Jul 3, 2023 at 3:02 PM Matt Young @.***> wrote:

PS: I do half expect you to find other PostgreSQL issues, because it's a bit less fast-and-loose about things than SQLite. They should all be fixable though!

— Reply to this email directly, view it on GitHub https://github.com/Brewtarget/brewtarget/issues/760#issuecomment-1619016621, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSNTYKD5Z3CN4GFUOAFZADXOMJLXANCNFSM6AAAAAAZ4YT2RI . You are receiving this because you authored the thread.Message ID: @.***>

marker5a commented 1 year ago

Should be fixed in PR #762

matty0ung commented 9 months ago

This fix is included in in https://github.com/Brewtarget/brewtarget/releases/tag/v3.0.10.