- 
                Notifications
    
You must be signed in to change notification settings  - Fork 30
 
Improve nestedProperties' type configuration #231
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
Improve nestedProperties' type configuration #231
Conversation
| 
           To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.  | 
    
| 
           I agree with the CLA  | 
    
| 
           Hey @pacyL2K19, thank you so much for this great contribution! I must admit, when looking into this I didn't have a great solution for it so I'm glad you've found this! The failing tests are due to some new behaviour on WCD, which we use for one journey test. I just pushed a fix for that so feel free to rebase on   | 
    
… configuration - Resolved incorrect handling of `nestedProperties` for non-object data types. - Introduced `ObjectDataType` and `PrimitiveDataType` for improved type distinction. - Updated `NestedPropertyCreate` and `NestedPropertyConfigCreate` to align with conditional `dataType` logic. - Improved type safety and consistency in data type configurations.
f6ffc07    to
    1bfedd7      
    Compare
  
    
          
 Thank you so much @tsmith023  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks again for the contribution! ❤️
| 
           Ah, I tried it out locally now that it's merged and still observe the same problem reported in the issue when   | 
    
          
 Hi @tsmith023  | 
    
| 
           For clarity, this  {
  "compilerOptions": {
    "target": "ESNext",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "allowSyntheticDefaultImports": true,
    "strict": false,
  },
}and this code: import { CollectionConfigCreate, dataType } from "weaviate-client";
function func(): CollectionConfigCreate {
  return {
    name: "Name",
    properties: [
      {
        name: 'images',
        dataType: 'object[]',
        nestedProperties: [
          {
            name: 'url',
            dataType: dataType.TEXT,
          },
          {
            name: 'caption',
            dataType: dataType.TEXT,
          },
          {
            name: 'number',
            dataType: dataType.NUMBER,
          }
        ],
      },
    ],
  };
}gives me compilation errors seen in the issue with the changes on   | 
    
This PR
"strict": false#203nestedPropertiesfor non-object data types:nestedPropertieswhenstrictmode was enabled, which is technically invalid.ObjectDataTypeandPrimitiveDataTypeto improve type distinction and prevent misuse.NestedPropertyCreateandNestedPropertyConfigCreateto align with conditional dataType logic.Current behavior (without the fix)
Strict Mode: true
Primitive types (
string,boolean, etc.) erroneously acceptnestedProperties, which is technically impossible.Example (Invalid but currently allowed):
Strict Mode: false
Both invalid and valid configurations trigger errors.
For instance, even proper configurations like the following are flagged:
Behavior With This Fix
Primitive Types:
Cannot accept
nestedPropertiesregardless of whether strict mode is enabled or not(desired behavior).Example (Now correctly flagged as invalid):
Object Types:
Continue to support deeply nested configurations without errors.
Example (Valid and supported):
The updated types now prevent invalid configurations and allow valid nested configurations without breaking existing functionality no matter the
strictflag in tsconfig