Repository: fwupd/fwupd (C)

Issue:
SQLite issue: `no such column: version_format`
**Describe the bug**

The `fwupd` services fails to start due to the following error:

```
Failed to load daemon: failed to load engine: Failed to prepare SQL to get history: no such column: version_format
```

Removing/renaming `/var/lib/fwupd/pending.db` fixes the problem. 

The file gets re-created, after inspecting it with `sqlite`, the `version_format` is now present in the `history` table.

**Steps to Reproduce**
- `fwupd get-devices`

**Expected behavior**
`fwupdmgr` doesn't fail.

**fwupd version information**
`fwupdmgr` fails with a DBus error.

After inspecting `fwdupd`'s logs, I see the log present in the description.

```shell
compile   org.freedesktop.fwupd         1.9.13
compile   com.hughsie.libxmlb           0.3.15
compile   org.freedesktop.Passim        0.1.5
compile   com.hughsie.libjcat           0.2.1
runtime   org.freedesktop.fwupd-efi     1.4
runtime   org.freedesktop.Passim        0.1.5
compile   org.freedesktop.gusb          0.4.8
runtime   com.hughsie.libjcat           0.2.1
runtime   org.freedesktop.gusb          0.4.8
runtime   org.kernel                    6.6.16-1-lts
runtime   org.freedesktop.fwupd         1.9.13
```

**Additional questions**

- Operating system and version: Arch Linux
- Have you tried rebooting? Yes
- Is this a regression? I don't know




Fix (patch):
diff --git a/docs/env.md b/docs/env.md
index cfc024efb4ca..b1f1e9c96986 100644
--- a/docs/env.md
+++ b/docs/env.md
@@ -11,7 +11,6 @@ with a non-standard filesystem layout.
 * `DISABLE_SSL_STRICT` disables strict SSL certificate checking, which may make
   downloading files work when using some antisocial corporate firewalls.
 * `FWUPD_CURL_VERBOSE` shows more information when downloading files
-* `FWUPD_DEVICE_TESTS_BASE_URI` sets the base URI when downloading firmware for the device-tests
 * `FWUPD_SUPPORTED` overrides the `-Dsupported_build` meson option at runtime
 * `FWUPD_VERBOSE` is set when running `--verbose`
 * `FWUPD_XMLB_VERBOSE` can be set to show Xmlb silo regeneration and quirk matches
diff --git a/src/fu-client-list.c b/src/fu-client-list.c
index a2ffa7204932..7a04f94caccb 100644
--- a/src/fu-client-list.c
+++ b/src/fu-client-list.c
@@ -64,7 +64,6 @@ fu_client_list_register(FuClientList *self, const gchar *sender)
 	FuClientListItem *item;
 
 	g_return_val_if_fail(FU_IS_CLIENT_LIST(self), NULL);
-	g_return_val_if_fail(sender != NULL, NULL);
 
 	/* already exists */
 	client = fu_client_list_get_by_sender(self, sender);
@@ -75,7 +74,7 @@ fu_client_list_register(FuClientList *self, const gchar *sender)
 	item = g_new0(FuClientListItem, 1);
 	item->self = self;
 	item->client = fu_client_new(sender);
-	if (self->connection != NULL) {
+	if (self->connection != NULL && sender != NULL) {
 		item->watcher_id =
 		    g_bus_watch_name_on_connection(self->connection,
 						   sender,
diff --git a/src/fu-daemon.c b/src/fu-daemon.c
index ebe3d819ffaa..0c84dad782d5 100644
--- a/src/fu-daemon.c
+++ b/src/fu-daemon.c
@@ -2192,23 +2192,31 @@ fu_daemon_client_list_removed_cb(FuClientList *client_list, FuClient *client, gp
 	fu_daemon_client_list_ensure_inhibit(self);
 }
 
+static void
+fu_daemon_set_connection(FuDaemon *self, GDBusConnection *connection)
+{
+	g_set_object(&self->connection, connection);
+	if (connection != NULL) {
+		g_autoptr(FuClientList) client_list = fu_client_list_new(connection);
+		g_signal_connect(client_list,
+				 "added",
+				 G_CALLBACK(fu_daemon_client_list_added_cb),
+				 self);
+		g_signal_connect(client_list,
+				 "removed",
+				 G_CALLBACK(fu_daemon_client_list_removed_cb),
+				 self);
+		g_set_object(&self->client_list, client_list);
+	}
+}
+
 static void
 fu_daemon_dbus_bus_acquired_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
 {
 	FuDaemon *self = FU_DAEMON(user_data);
 	g_autoptr(GError) error = NULL;
 
-	self->connection = g_object_ref(connection);
-	self->client_list = fu_client_list_new(self->connection);
-	g_signal_connect(self->client_list,
-			 "added",
-			 G_CALLBACK(fu_daemon_client_list_added_cb),
-			 self);
-	g_signal_connect(self->client_list,
-			 "removed",
-			 G_CALLBACK(fu_daemon_client_list_removed_cb),
-			 self);
-
+	fu_daemon_set_connection(self, connection);
 	fu_daemon_register_object(self);
 
 	/* connect to D-Bus directly */
@@ -2261,7 +2269,7 @@ fu_daemon_dbus_new_connection_cb(GDBusServer *server,
 				 gpointer user_data)
 {
 	FuDaemon *self = FU_DAEMON(user_data);
-	g_set_object(&self->connection, connection);
+	fu_daemon_set_connection(self, connection);
 	g_signal_connect(connection,
 			 "closed",
 			 G_CALLBACK(fu_daemon_dbus_connection_closed_cb),
diff --git a/src/fu-history.c b/src/fu-history.c
index 21a4fd3e8221..3be03c3a740c 100644
--- a/src/fu-history.c
+++ b/src/fu-history.c
@@ -21,7 +21,20 @@
 #include "fu-history.h"
 #include "fu-security-attr-common.h"
 
-#define FU_HISTORY_CURRENT_SCHEMA_VERSION 10
+/*
+ * v1	legacy schema
+ * v2	initial schema
+ * v3	add checksum_device to history
+ * v4	add protocol to history
+ * v5	create table approved_firmware
+ * v6	create table blocked_firmware
+ * v7	create table hsi_history
+ * v8	add release_id to history
+ * v9	add appstream_id to history
+ * v10	add version_format to history
+ * v11	no changes, bumped due to bungled migration to v10
+ */
+#define FU_HISTORY_CURRENT_SCHEMA_VERSION 11
 
 static void
 fu_history_finalize(GObject *object);
@@ -466,11 +479,12 @@ fu_history_create_or_migrate(FuHistory *self, guint schema_ver, GError **error)
 	case 8:
 		if (!fu_history_migrate_database_v8(self, error))
 			return FALSE;
-		break;
 	/* fall through */
 	case 9:
+	case 10:
 		if (!fu_history_migrate_database_v9(self, error))
 			return FALSE;
+		/* no longer fall through */
 		break;
 	default:
 		/* this is probably okay, but return an error if we ever delete
diff --git a/src/fu-util.c b/src/fu-util.c
index f30cb0f2b509..6b29a43a75a0 100644
--- a/src/fu-util.c
+++ b/src/fu-util.c
@@ -891,7 +891,6 @@ fu_util_device_test_step(FuUtilPrivate *priv,
 	JsonArray *json_array;
 	const gchar *url;
 	const gchar *emulation_url = NULL;
-	const gchar *baseuri = g_getenv("FWUPD_DEVICE_TESTS_BASE_URI");
 	g_autofree gchar *filename = NULL;
 	g_autofree gchar *url_safe = NULL;
 	g_autoptr(GBytes) fw = NULL;
@@ -900,7 +899,6 @@ fu_util_device_test_step(FuUtilPrivate *priv,
 	/* send this data to the daemon */
 	if (helper->use_emulation) {
 		g_autofree gchar *emulation_filename = NULL;
-		g_autofree gchar *emulation_safe = NULL;
 		g_autoptr(GBytes) emulation_data = NULL;
 
 		/* just ignore anything without emulation data */
@@ -908,15 +906,9 @@ fu_util_device_test_step(FuUtilPrivate *priv,
 			return TRUE;
 
 		emulation_url = json_object_get_string_member(json_obj, "emulation-url");
-		if (baseuri != NULL) {
-			g_autofree gchar *basename = g_path_get_basename(emulation_url);
-			emulation_safe = g_build_filename(baseuri, basename, NULL);
-		} else {
-			emulation_safe = g_strdup(emulation_url);
-		}
-		emulation_filename = fu_util_download_if_required(priv, emulation_safe, error);
+		emulation_filename = fu_util_download_if_required(priv, emulation_url, error);
 		if (emulation_filename == NULL) {
-			g_prefix_error(error, "failed to download %s: ", emulation_safe);
+			g_prefix_error(error, "failed to download %s: ", emulation_url);
 			return FALSE;
 		}
 		emulation_data = fu_bytes_get_contents(emulation_filename, error);
@@ -937,21 +929,15 @@ fu_util_device_test_step(FuUtilPrivate *priv,
 
 	/* build URL */
 	url = json_object_get_string_member(json_obj, "url");
-	if (baseuri != NULL) {
-		g_autofree gchar *basename = g_path_get_basename(url);
-		url_safe = g_build_filename(baseuri, basename, NULL);
-	} else {
-		url_safe = g_strdup(url);
-	}
-	filename = fu_util_download_if_required(priv, url_safe, error);
+	filename = fu_util_download_if_required(priv, url, error);
 	if (filename == NULL) {
-		g_prefix_error(error, "failed to download %s: ", url_safe);
+		g_prefix_error(error, "failed to download %s: ", url);
 		return FALSE;
 	}
 
 	/* log */
 	json_builder_set_member_name(helper->builder, "url");
-	json_builder_add_string_value(helper->builder, url_safe);
+	json_builder_add_string_value(helper->builder, url);
 
 	/* install file */
 	priv->flags |= FWUPD_INSTALL_FLAG_ALLOW_OLDER;