diff options
author | Tor Egge <Tor.Egge@verizonmedia.com> | 2019-03-04 12:04:22 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@verizonmedia.com> | 2019-03-04 12:04:22 +0100 |
commit | 224397d0ef2f5ac20cd7eb0efb8a108bce0632bc (patch) | |
tree | 8fb61d7e91db04ff0784e48b80dfeac56b6b257c /searchcore | |
parent | 9ee9e0a5517d9b5ab6378b3002341215bfb191ef (diff) |
Don't create imported attribute if target attribute is missing.
Diffstat (limited to 'searchcore')
2 files changed, 21 insertions, 4 deletions
diff --git a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp index f6da0c75d62..062586b1d0f 100644 --- a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp +++ b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp @@ -69,8 +69,11 @@ struct MyDocumentDBReference : public MockDocumentDBReference { } virtual std::shared_ptr<search::attribute::ReadableAttributeVector> getAttribute(vespalib::stringref name) override { auto itr = attributes.find(name); - ASSERT_TRUE(itr != attributes.end()); - return itr->second; + if (itr != attributes.end()) { + return itr->second; + } else { + return std::shared_ptr<search::attribute::ReadableAttributeVector>(); + } } void addIntAttribute(vespalib::stringref name) { attributes[name] = AttributeFactory::createAttribute(name, Config(BasicType::INT32)); @@ -82,6 +85,9 @@ struct MyDocumentDBReference : public MockDocumentDBReference { MockGidToLidChangeHandler &getGidToLidChangeHandler() { return *_gidToLidChangeHandler; } + void removeAttribute(vespalib::stringref name) { + attributes.erase(name); + } }; struct MyReferenceRegistry : public IDocumentDBReferenceRegistry { @@ -306,6 +312,15 @@ TEST_F("require that imported attributes are instantiated with search cache if v f.assertImportedAttribute("imported_b", "other_ref", "target_b", true, repo->get("imported_b")); } +TEST_F("require that missing target attribute prevents creation of imported attribute", Fixture) +{ + f.parentReference->removeAttribute("target_a"); + auto repo = f.resolve(); + EXPECT_EQUAL(1u, repo->size()); + EXPECT_FALSE(repo->get("imported_a")); + EXPECT_TRUE(repo->get("imported_b")); +} + TEST_F("require that listeners are added", Fixture) { f.resolve(); diff --git a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp index 95da27cf3bd..0d83eea261a 100644 --- a/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp +++ b/searchcore/src/vespa/searchcore/proton/reference/document_db_reference_resolver.cpp @@ -146,8 +146,10 @@ DocumentDBReferenceResolver::createImportedAttributesRepo(const IAttributeManage auto targetDocumentDB = getTargetDocumentDB(refAttr->getName()); auto targetAttr = targetDocumentDB->getAttribute(attr.targetfield); auto targetDocumentMetaStore = targetDocumentDB->getDocumentMetaStore(); - auto importedAttr = ImportedAttributeVectorFactory::create(attr.name, refAttr, documentMetaStore, targetAttr, targetDocumentMetaStore, useSearchCache); - result->add(importedAttr->getName(), importedAttr); + if (targetAttr) { + auto importedAttr = ImportedAttributeVectorFactory::create(attr.name, refAttr, documentMetaStore, targetAttr, targetDocumentMetaStore, useSearchCache); + result->add(importedAttr->getName(), importedAttr); + } } } return result; |