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

Test to support custom field sources. #2146

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

elexisvenator
Copy link
Contributor

Still a work in progress.

Using string-backed struct as a custom object.
Currently works with CustomId and CustomId?. Does not yet work with CustomId[].

Once working, can be added to documentation.

Using string-backed struct as a custom object.
Currently works with `CustomId` and `CustomId?`. Does not yet work with `CustomId[]`.
@jeremydmiller jeremydmiller added this to the 5.1.0 milestone Mar 31, 2022
@elexisvenator
Copy link
Contributor Author

@jeremydmiller I might need some help to make the CustomId[] scenario work, I'm a bit lost with how to make detection of arrays work.

@elexisvenator
Copy link
Contributor Author

I cleared a bunch of issues by registering a mapping for CustomId to dbtype in the PostgresqlProvider.
That leaves array contains, which i know what this issue is -
In most places where a constant value for the custom id is passed in, it hits the CustomIdField.CreateComparison() method. This allows me to coerce the constant CustomId that is passed in into the raw value type the db needs.

            var def = new CommandParameter(((CustomId)value.Value).Value);
            return new ComparisonFilter(this, def, op);

But for the array.contains scenario specifically this doesn't happen. Instead the field maps to ArrayField, and the constant is converted to a CommandParameter in the ContainsIdSelectorStatement constructor. The CommandParameter correctly asserts what the dbparametertype should be but doesnt do any conversion on the CustomId, so the npgsql command fails when it executes, not knowing how to process CustomId as varchar.

I think what needs to happen is when registering a mapping in the PostgresProvider for the custom id, some sort of function needs to be passed in eg Func<TInputType, TRawType>. This could then be used to preprocess the custom id whenever a lookup is done. This would be a pretty significant change in weasel though.

@jeremydmiller
Copy link
Member

I think there's an evil downcast in the Linq parsing code to ArrayField that's messing this up.

Doesnt serve a purpose for the tests
@jeremydmiller
Copy link
Member

@elexisvenator Is the only thing missing at this point the Contains() operation?

@jeremydmiller
Copy link
Member

Oh, and I could probably try to finish this off on Monday if you wanted.

@mysticmind mysticmind modified the milestones: 5.1.0, 5.1.1 Apr 8, 2022
@elexisvenator
Copy link
Contributor Author

elexisvenator commented Apr 10, 2022

I went through all documented functions and this is the list of functions that fail:

  • CustomId,IsOneOf()
  • CustomId[].Any() (with predicate)
  • !CustomId[].Any() (with predicate)
  • CustomId[].Contains()
  • !CustomId[].Contains()
  • CustomId[].IsOneOf()

They all seem to be failing on the same reason. (Can't map a customid value to a varchar postgres value).

@jeremydmiller jeremydmiller removed this from the 5.3.0 milestone May 2, 2022
@elexisvenator
Copy link
Contributor Author

Tried working around this and found even more hurdles.

While queries against projections with a customid DuplicateField will generate without failing, the code to create the index in the first place will fail. As will the generated db functions for creating/upserting records. All of these fail with the same issue - npgsql fails to figure out what primitive type to use.

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

Successfully merging this pull request may close these issues.

3 participants