Skip to content

Query Assets - Facing API error when using projection involving multi-word fields #146

@ShriramS-Emerson

Description

@ShriramS-Emerson

When using projection in the query_assets method of the AssetManagementClient, projection fields that are of single words (e.g., ID, NAME) work as expected. However, if we try to pass any multi-word fields (e.g., EXTERNAL_CALIBRATION, MODEL_NAME), the API returns an error:

message="Error parsing projection: 'Property 'EXTERNAL_CALIBRATION' does not exist on type NationalInstruments.AssetService.WebApi.Repository.Assets.Model.AssetEntry.'."

args=["Property 'EXTERNAL_CALIBRATION' does not exist on type NationalInstruments.AssetService.WebApi.Repository.Assets.Model.AssetEntry."]

It seems that the issue is because the format expected by the actual API is camelCase, but the client library doesn't perform any case conversion for the projection fields which are of UPPER_SNAKE_CASE. Verified that this is the issue by trying the client with the inclusion of a case converter.

def _snake_case_to_camel(snake_str):
    parts = snake_str.split('_')
    return parts[0] + ''.join(word.capitalize() for word in parts[1:])
        
projection_str = (
    f"new({', '.join(_snake_case_to_camel(projection.name) for projection in query.projection)})"
    if query.projection
    else None
)

Not sure if this is how this issue has to be resolved. Because I couldn't get to see we are doing anything similar to this in other clients - not any explicit case conversion of projection fields.

Thank you for your attention to this issue!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions