From b00936b1e2cb727d81d9000adeb382ae81b7cde6 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Fri, 19 Jul 2024 16:07:33 -0400 Subject: [PATCH] Fix REST CI segfault. --- test/src/unit-rest-array-schema-load.cc | 10 ++++------ tiledb/sm/array_schema/array_schema_operations.cc | 11 ++++++----- tiledb/sm/array_schema/array_schema_operations.h | 2 +- tiledb/sm/c_api/tiledb.cc | 10 ++++++---- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/test/src/unit-rest-array-schema-load.cc b/test/src/unit-rest-array-schema-load.cc index 8cda912412a..41ef4878ab8 100644 --- a/test/src/unit-rest-array-schema-load.cc +++ b/test/src/unit-rest-array-schema-load.cc @@ -58,11 +58,6 @@ TEST_CASE_METHOD( "[rest][array-schema][simple-load]") { create_array(); - auto config = ctx_.config(); - config.set("rest.load_enumerations_on_array_open", "false"); - vfs_test_setup_.update_config(config.ptr().get()); - ctx_ = vfs_test_setup_.ctx(); - ArraySchema schema = Array::load_schema(ctx_, uri_); auto matcher = Catch::Matchers::ContainsSubstring( "Enumeration 'my_enum' is not loaded."); @@ -70,7 +65,7 @@ TEST_CASE_METHOD( ArraySchemaExperimental::get_enumeration(ctx_, schema, "my_enum"), matcher); - // Schema was constructed prior to creating the array, the array URI is empty. + // schema_ was constructed prior to creating the array, so array URI is empty. // Set the schema's array_uri without opening the array. schema_.ptr()->array_schema_->set_array_uri(sm::URI(uri_)); test::schema_equiv( @@ -88,6 +83,9 @@ TEST_CASE_METHOD( REQUIRE_NOTHROW( ArraySchemaExperimental::get_enumeration(ctx_, schema, "my_enum")); + // schema_ was constructed prior to creating the array, so array URI is empty. + // Set the schema's array_uri without opening the array. + schema_.ptr()->array_schema_->set_array_uri(sm::URI(uri_)); test::schema_equiv( *schema.ptr()->array_schema_, *schema_.ptr()->array_schema_); } diff --git a/tiledb/sm/array_schema/array_schema_operations.cc b/tiledb/sm/array_schema/array_schema_operations.cc index b8feae1b309..b4e03e70026 100644 --- a/tiledb/sm/array_schema/array_schema_operations.cc +++ b/tiledb/sm/array_schema/array_schema_operations.cc @@ -130,7 +130,7 @@ void store_array_schema( } shared_ptr load_array_schema( - const Context& ctx, const URI& uri, const Config* config) { + const Context& ctx, const URI& uri, const Config& config) { // Check array name if (uri.is_invalid()) { throw std::runtime_error("Failed to load array schema; Invalid array URI"); @@ -138,8 +138,8 @@ shared_ptr load_array_schema( if (uri.is_tiledb()) { auto& rest_client = ctx.rest_client(); - auto array_schema_response = rest_client.post_array_schema_from_rest( - config ? *config : ctx.resources().config(), uri, 0, UINT64_MAX); + auto array_schema_response = + rest_client.post_array_schema_from_rest(config, uri, 0, UINT64_MAX); return std::move(std::get<0>(array_schema_response)); } else { // Create key @@ -161,9 +161,10 @@ shared_ptr load_array_schema( auto&& array_schema_latest = array_dir->load_array_schema_latest(key, tracker); - bool incl_enums = config->get( + // Load enumerations if config option is set. + bool incl_enums = config.get( "rest.load_enumerations_on_array_open", Config::must_find); - if (config && incl_enums) { + if (incl_enums) { std::vector enmr_paths_to_load; auto enmr_names = array_schema_latest->get_enumeration_names(); for (auto& name : enmr_names) { diff --git a/tiledb/sm/array_schema/array_schema_operations.h b/tiledb/sm/array_schema/array_schema_operations.h index 9b4cdcf0d51..43d2f1c7cc7 100644 --- a/tiledb/sm/array_schema/array_schema_operations.h +++ b/tiledb/sm/array_schema/array_schema_operations.h @@ -77,7 +77,7 @@ void store_array_schema( * @param config TileDB Config. If null, the context config will be used. */ shared_ptr load_array_schema( - const Context& ctx, const URI& uri, const Config* config = nullptr); + const Context& ctx, const URI& uri, const Config& config); } // namespace tiledb::sm diff --git a/tiledb/sm/c_api/tiledb.cc b/tiledb/sm/c_api/tiledb.cc index d5652cae59f..7918d4a6705 100644 --- a/tiledb/sm/c_api/tiledb.cc +++ b/tiledb/sm/c_api/tiledb.cc @@ -490,8 +490,9 @@ int32_t tiledb_array_schema_load( throw CAPIStatusException("Failed to allocate TileDB array schema object"); } + // Use a default constructed config to load the schema with default options. (*array_schema)->array_schema_ = - load_array_schema(ctx->context(), sm::URI(array_uri)); + load_array_schema(ctx->context(), sm::URI(array_uri), sm::Config()); return TILEDB_OK; } @@ -511,10 +512,11 @@ int32_t tiledb_array_schema_load_with_options( throw CAPIStatusException("Failed to allocate TileDB array schema object"); } - // Check array name - tiledb::sm::URI uri(array_uri); + // Use passed config or context config to load the schema with set options. (*array_schema)->array_schema_ = load_array_schema( - ctx->context(), uri, config ? &config->config() : nullptr); + ctx->context(), + sm::URI(array_uri), + config ? config->config() : ctx->config()); return TILEDB_OK; }