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

Tests and documentation for wrong property tags issue #7599

Merged
merged 30 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
243ad7c
Added tests and documentation for wrong property tags issue
Abhijeet-Bentley Jan 24, 2025
bc3f530
Removed unnecessary import
Abhijeet-Bentley Jan 24, 2025
96a1200
Recommitting since last PR failed
Abhijeet-Bentley Jan 24, 2025
8cb3ae8
Merge branch 'master' into abhi/wrong-property-tags-testing
akshay05n Jan 24, 2025
936262f
Fix : "using" deprecated
Abhijeet-Bentley Jan 27, 2025
15fe041
Documentation changes
Abhijeet-Bentley Jan 27, 2025
0effcc8
removed ".only" from my test case
Abhijeet-Bentley Jan 27, 2025
e043ff1
Test case and documentation changes
Abhijeet-Bentley Jan 28, 2025
2cd2ad2
Removed ".only" from my test case
Abhijeet-Bentley Jan 28, 2025
b8b2cd7
Merge branch 'master' into abhi/wrong-property-tags-testing
RohitPtnkr1996 Jan 28, 2025
ee678fa
Minor documentation change
Abhijeet-Bentley Jan 28, 2025
b0bb7ee
Merge branch 'abhi/wrong-property-tags-testing' of https://github.com…
Abhijeet-Bentley Jan 28, 2025
298e7e2
Merge branch 'master' into abhi/wrong-property-tags-testing
Abhijeet-Bentley Jan 29, 2025
1f49228
Corrected wrong schema in a test and some documentation
Abhijeet-Bentley Jan 29, 2025
f9f8a86
Changelog entry
Abhijeet-Bentley Jan 29, 2025
bfabfbf
Merge branch 'abhi/wrong-property-tags-testing' of https://github.com…
Abhijeet-Bentley Jan 29, 2025
7aac56b
Merge branch 'master' into abhi/wrong-property-tags-testing
Abhijeet-Bentley Jan 29, 2025
92aa389
Test case fix
Abhijeet-Bentley Jan 29, 2025
07e14a0
Merge branch 'abhi/wrong-property-tags-testing' of https://github.com…
Abhijeet-Bentley Jan 29, 2025
24c4844
Merge branch 'master' into abhi/wrong-property-tags-testing
Abhijeet-Bentley Jan 30, 2025
f0bc10a
Removed test case and corrected description
Abhijeet-Bentley Jan 30, 2025
041c75b
Merge branch 'master' into abhi/wrong-property-tags-testing
Abhijeet-Bentley Jan 31, 2025
a6b555c
Hard coding ECXml version in test case
Abhijeet-Bentley Jan 31, 2025
a393d06
Merge branch 'abhi/wrong-property-tags-testing' of https://github.com…
Abhijeet-Bentley Jan 31, 2025
62df65d
Description change
Abhijeet-Bentley Jan 31, 2025
ebc89c6
Merging two doc files into one
Abhijeet-Bentley Jan 31, 2025
9b25eb2
Documentation change
Abhijeet-Bentley Jan 31, 2025
f981b68
Merge branch 'master' into abhi/wrong-property-tags-testing
Abhijeet-Bentley Jan 31, 2025
3529da4
Merge branch 'master' into abhi/wrong-property-tags-testing
Abhijeet-Bentley Feb 3, 2025
80d878a
Merge branch 'master' into abhi/wrong-property-tags-testing
Abhijeet-Bentley Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-backend",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/core-backend"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/ecschema-metadata",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/ecschema-metadata"
}
4 changes: 2 additions & 2 deletions core/backend/src/test/ecdb/ECSqlStatement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3127,8 +3127,8 @@ describe("ECSqlStatement", () => {
<ECProperty propertyName="booleanProperty" typeName="boolean"/>
<ECProperty propertyName="blobProperty" typeName="binary"/>
<ECProperty propertyName="doubleProperty" typeName="double"/>
<ECProperty propertyName="customIdProperty" typeName="id"/>
<ECProperty propertyName="customIdSetProperty" typeName="idSet"/>
rschili marked this conversation as resolved.
Show resolved Hide resolved
<ECProperty propertyName="customIdProperty" typeName="string"/>
<ECProperty propertyName="customIdSetProperty" typeName="string"/>
<ECProperty propertyName="intProperty" typeName="int"/>
<ECProperty propertyName="longProperty" typeName="long"/>
<ECProperty propertyName="stringProperty" typeName="string"/>
Expand Down
43 changes: 43 additions & 0 deletions core/ecschema-metadata/src/test/Metadata/Schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,49 @@ describe("Schema", () => {
deserializeAndTestJSONSync(JSON.stringify(schemaJson), testRelationshipStrength);
await testSerialization(_schema, false, unsupportedVersionError);
});

it("should throw an error for version previous to current, when encountered an unknown type", async () => {
ColinKerr marked this conversation as resolved.
Show resolved Hide resolved
const schemaXml = `<?xml version="1.0" encoding="utf-8"?>
<ECSchema schemaName="Test" alias="test" version="1.0.0" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.${Schema.currentECSpecMajorVersion}.${Schema.currentECSpecMinorVersion}">
<ECStructClass typeName="PrimStruct">
<ECProperty propertyName="p2d" typeName="Point2d" />
<ECProperty propertyName="p3d" typeName="Point3d" />
</ECStructClass>
<ECEntityClass typeName="UseOfWrongPropertyTags">
<ECProperty propertyName="Struct" typeName="PrimStruct" />
<ECStructArrayProperty propertyName="Struct_Array" typeName="PrimStruct" />
</ECEntityClass>
</ECSchema>`;

_schema = new Schema(_context);
try {
await _xmlReader.readSchema(_schema, new DOMParser().parseFromString(schemaXml));
} catch (err: any) {
assert.equal(err.message, `The provided primitive type, Test.PrimStruct, is not a valid PrimitiveType or Enumeration.`);
}
});

it("should throw an error for current version, when encountered an unknown type", async () => {
const schemaXml = `<?xml version="1.0" encoding="utf-8"?>
<ECSchema schemaName="Test" alias="test" version="1.0.0" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.${Schema.currentECSpecMajorVersion}.${Schema.currentECSpecMinorVersion - 1}">
<ECStructClass typeName="PrimStruct">
<ECProperty propertyName="p2d" typeName="Point2d" />
<ECProperty propertyName="p3d" typeName="Point3d" />
</ECStructClass>
<ECEntityClass typeName="UseOfWrongPropertyTags">
<ECProperty propertyName="Struct" typeName="PrimStruct" />
<ECStructArrayProperty propertyName="Struct_Array" typeName="PrimStruct" />
</ECEntityClass>
</ECSchema>`;

_schema = new Schema(_context);
try {
await _xmlReader.readSchema(_schema, new DOMParser().parseFromString(schemaXml));
} catch (err: any) {
assert.equal(err.message, `The provided primitive type, Test.PrimStruct, is not a valid PrimitiveType or Enumeration.`);
}
});

});
});

Expand Down
12 changes: 12 additions & 0 deletions docs/learning/backend/HandlingUnknownAndWrongSchemaElements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Handling of schemas with unknown/wrong elements
ColinKerr marked this conversation as resolved.
Show resolved Hide resolved

All schemas using the current or older ECXml versions will fail to deserialize if they encounter incorrect or unknown property tags.
When this occurs, an error will be logged, clearly stating the cause of failure and explaining that deserialization process cannot proceed
due to the unrecognized properties.

### Behavior of wrong property tags across different versions during deserialization

| Version | Behavior during deserialization |
| - | - |
| Versions older than latest (known to ECDb runtime) | Throws an error |
| Latest Version | Throws an error |
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
## Handling of newer schemas by older ECDb runtimes

A schema with a newer ECXml version might contain elements not known to the ECDb runtime being used as it's older.
A read compatible but write incompatible schema (only ECXml minor version incremented) cannot be imported into the iModel.
However, the schema can be deserialized and loaded into memory.
This schema is also then restricted from being serialized to a file or a string.
A schema with a newer ECXml version might contain elements not recognized by the older ECDb runtime. Additionally, a schema might include incorrect elements, such as an ECProperty tag used to denote a struct inside an entity class. A read-compatible but write-incompatible schema (with only an ECXml minor version increment) cannot be imported into the iModel. However, any schema, except for version 3.2 of the ECXml schema, can be deserialized and loaded into memory. This schema version is also restricted from being serialized to a file or a string.

### Behavior during deserialization
### Behavior of newer schemas during deserialization

| Schema Element or Attribute | Behavior during deserialization |
| - | - |
Expand All @@ -17,7 +14,6 @@ This schema is also then restricted from being serialized to a file or a string.
| Unknown backing type in ECEnumeration | Defaults to `string` |
| Unknown relationship class strength | Defaults to `referencing` |


### Reading a newer schema already present in a newer iModel

A newer iModel may be containing schemas that are write incompatible due to elements unknown to the ECDb runtime being used.
Expand All @@ -33,4 +29,4 @@ When reading such a schema with an older ECDb runtime, a reduced form of the sch
| Unknown backing type in ECEnumeration | The enumeration will not be loaded |
| Unknown relationship class strength | The relationship class and it's corresponding navigation properties will not be loaded |
| Unknown relationship class direction | The relationship class and it's corresponding navigation properties will not be loaded |
| Unknown navigation property direction | The navigation property will not be loaded |
| Unknown navigation property direction | The navigation property will not be loaded |
4 changes: 2 additions & 2 deletions docs/learning/backend/IModelDb.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ With the general evolution of schemas, there may come a time when a schema has b
A write-incompatable schema can be loaded, but it can be neither imported into an iModel, nor can it be serialized to a file or string.

Such a schema is likely to contain elements that are unknown to the current ECDb runtime being used.
To know more about how these unknown elements are handled, refer to [Handling Unknown Schema Elements](./HandlingUnknownSchemaElements.md)
To know more about how these unknown elements are handled, refer to [Handling Unknown And Wrong Schema Elements For Newer Versions](./HandlingUnknownAndWrongSchemaElementsForNewerVersions.md)

To be able to perform read and write operations on a schema with a newer ECXml version, it us recommended to upgrade the ECDb runtime to a version that supports the ECXml version.
To be able to perform read and write operations on a schema with a newer ECXml version, it us recommended to upgrade the ECDb runtime to a version that supports the ECXml version.