Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Level document structure requires a base-class for sub-sub-documents #2101

Open
Tra5is opened this issue Feb 21, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@Tra5is
Copy link

Tra5is commented Feb 21, 2024

Describe the bug
To create a document structure that has more than two levels of document references (Doc -> subDoc -> subDoc... etc) the odd-numbered levels are required to have a base-class. Otherwise the error ascribed_type_not_subsumed is returned when submitting new documents.

The issue appears to occur every other sub-document level. Effectively the even leveled sub-documents. So, levels 3 (SubDoc2), 5 (SubDoc4), etc require a base-class.

Part of this bug is that the error is not well documented and that the meaning of 'subsumed' is not clear in this context.

To Reproduce
Using the schema:

[
    {
        "@base": "terminusdb:///data/",
        "@schema": "terminusdb:///schema#",
        "@type": "@context"
    },
    {
        "@base": "SubDoc2/",
        "@id": "SubDoc2",
        "@key": {
            "@type": "ValueHash"
        },
        "@subdocument": [],
        "@type": "Class",
        "Sub2Prop": "xsd:string"
    },
    {
        "@base": "Top/",
        "@id": "TopLevelDoc",
        "@key": {
            "@type": "Random"
        },
        "@type": "Class",
        "Prop1": "xsd:string",
        "SubDoc": {
            "@class": "SubDoc1",
            "@type": "Optional"
        }
    },
    {
        "@base": "SubDoc1/",
        "@id": "SubDoc1",
        "@key": {
            "@type": "Random"
        },
        "@subdocument": [],
        "@type": "Class",
        "Sub1Prop": "xsd:string",
        "SubSubDoc": {
            "@class": "SubDoc2",
            "@type": "Optional"
        }
    }
]

To represent a multi-level document:

{
	"Prop1": "Top",
	"SubDoc": {
	  "Sub1Prop": "Sub",
	  "SubSubDoc": {
	    "Sub2Prop": "SubSub"
	  }
	}
}

and creating the document with a rest POST call (from powershell):

$body = @"
{
	"Prop1": "Top",
	"SubDoc": 
	{
	  "Sub1Prop": "Sub",
	  "SubSubDoc": {
	    "@type": "terminusdb:///schema#SubDoc2",
	    "Sub2Prop": "SubSub"
	  }
	}
}
"@

$user = ""
$pass = ""
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
    Authorization = $basicAuthValue
    'Content-Type' = 'application/json'
}

Invoke-WebRequest `
	-Uri "http://<your terminus db host>/api/document/admin/test3/local/branch/main?message=Test&author=Test&graph_type=instance&full_replace=false&raw_json=false" `
	-Method POST `
	-Body $body `
	-Headers $headers

Results in the error:

"reason": {
              "terminusdb:///schema#SubSubDoc": {
                "@type": "ascribed_type_not_subsumed",
                "ascribed_type": "terminusdb:///schema#SubDoc2",
                "document": {
                  "@type": "terminusdb:///schema#SubDoc2",
                  "Sub2Prop": "SubSub"
                },
                "required_type": "terminusdb:///schema#SubDoc2"
              }
            }

The error can be avoided by adding a base-class to SubDoc2 and referencing that from SubDoc1.

[
    {
        "@base": "terminusdb:///data/",
        "@schema": "terminusdb:///schema#",
        "@type": "@context"
    },
    {
        "@base": "SubDoc2/",
        "@id": "SubDoc2",
        "@inherits": "SubDocBase2",
        "@key": {
            "@type": "ValueHash"
        },
        "@subdocument": [],
        "@type": "Class",
        "Sub2Prop": "xsd:string"
    },
    {
        "@base": "Top/",
        "@id": "TopLevelDoc",
        "@key": {
            "@type": "Random"
        },
        "@type": "Class",
        "Prop1": "xsd:string",
        "SubDoc": {
            "@class": "SubDoc1",
            "@type": "Optional"
        }
    },
    {
        "@abstract": [],
        "@base": "SubDocBase2/",
        "@id": "SubDocBase2",
        "@key": {
            "@type": "Random"
        },
        "@subdocument": [],
        "@type": "Class"
    },
    {
        "@base": "SubDoc1/",
        "@id": "SubDoc1",
        "@key": {
            "@type": "Random"
        },
        "@subdocument": [],
        "@type": "Class",
        "Sub1Prop": "xsd:string",
        "SubSubDoc": {
            "@class": "SubDocBase2",
            "@type": "Optional"
        }
    }
]

Expected behavior

The extra base class should not be required.

Screenshots
image

Info (please complete the following information):

  • OS: Ubuntu 22.04.3 LTS
  • Installed via snap (version 11.1.9), run via terminusdb serve
@Tra5is Tra5is added the bug Something isn't working label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant