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

Guid primitive literals non compliant with OASIS OData url conventions (v4.0) #155

Closed
kinekt4 opened this issue Jun 5, 2024 · 6 comments

Comments

@kinekt4
Copy link

kinekt4 commented Jun 5, 2024

I'm using a REST api and have been successful filtering by string and decimals etc.

But when filtering a guid column I get a 400 Bad Response with the following error:

A binary operator with incompatible types was detected. Found operand types 'Edm.Guid' and 'Edm.String' for operator kind 'Equal'.

I'm currently filtering like this:

$item = $odataClient->from('Item')->where('id', '=', 'ec11-80f1-0022489308a6')->get();

I see that the issue is related to the single quotes being added to the value in Grammar::prepareValue().

To prevent single quotes being added, it seems I have to explicitly define the type as a prefix Grammar::isSpecialPrimitiveDataType()

return preg_match("/^(binary|datetime|guid|time|datetimeoffset)(\'[\w\:\-\.]+\')$/i", $value);

So I've modified the guid value to something like this:

$item = $odataClient->from('Item')->where('id', '=', "guid'ec11-80f1-0022489308a6'")->get();

Which resulted in a different error.

Can anyone suggest anything else I can try?

Thanks!

  • odata-client: v0.7.3
  • REST API: MS Dynamics 365 (D365)

Edit

  • It seems that the API I'm using (MS Dynamics 365) doesn't support the guid'<value>' syntax
  • And there's no way to passthrough the value without the value being stringified by this library (I believe)
  • I'm proposing a possible fix here:
  • Passthrough raw values without it being stringified #156

Edit 02

  • I just noticed this PR:
  • Where raw #105
  • Which deals with passing through the whole raw statement

Rest API

Test done via Postman

Filter Response
id eq 'ec11-80f1-0022489308a6' Error: A binary operator with incompatible types was detected.
Found operand types 'Edm.Guid' and 'Edm.String' for operator kind 'Equal'.
id eq guid'ec11-80f1-0022489308a6' Error: Unrecognized 'Edm.String' literal...
id eq ec11-80f1-0022489308a6 OK
@kinekt4 kinekt4 changed the title Q: How to filter by column with primitive type (such as Edm.Guid) How to passthrough raw values without it being stringified Jun 5, 2024
@kinekt4 kinekt4 changed the title How to passthrough raw values without it being stringified How do I passthrough raw values without it being stringified? Jun 5, 2024
@kinekt4
Copy link
Author

kinekt4 commented Jun 5, 2024

@kinekt4 kinekt4 changed the title How do I passthrough raw values without it being stringified? Guid primitive literals non compliant with OASIS OData url conventions (v4.0) Jun 5, 2024
@kinekt4
Copy link
Author

kinekt4 commented Jun 6, 2024

@kinekt4
Copy link
Author

kinekt4 commented Jun 6, 2024

Whereas PR #105 allows users to pass through the whole raw expression; eg.

$whereRaw = "id eq ec11-80f1-0022489308a6";
$item = $odataClient->from('Item')->whereRaw($whereRaw)->get();

My PR #156 only aims to pass through the raw value, while maintaining the regular syntax as before

$item = $odataClient->from('Item')->where('id', '=', "raw'ec11-80f1-0022489308a6'")->get();

@kinekt4
Copy link
Author

kinekt4 commented Jun 6, 2024

I found my solution in #137, I should do this instead (undocumented):

$item = $odataClient->from('Item')->whereKey('ec11-80f1-0022489308a6')->get();

@kinekt4 kinekt4 closed this as completed Jun 6, 2024
@anderly
Copy link
Member

anderly commented Jul 29, 2024

Will see about updating samples and docs with this.

@anderly
Copy link
Member

anderly commented Jul 29, 2024

@kinekt4, also curious if the following would work for your case if it's an ID/PK field:

    $odataClient->from('Item')->find('ec11-80f1-0022489308a6');

This is example is on the wiki, but wanted to check if it worked in your example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants