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

Invalid SQL generated with NGram search & .Any when multi tenanted - 7.0.0 - beta 4 #2916

Closed
arildboifot opened this issue Jan 18, 2024 · 1 comment
Assignees
Labels
Milestone

Comments

@arildboifot
Copy link

When adding .MultiTenanted() to the document mapping the query crashes with the following exception. Without .MultiTenanted everything works as expected.

      Marten encountered an exception executing 
      select d.id, d.data from public.mt_doc_ngramdoc as d where (d.tenant_id = $1  and  (public.mt_grams_vector(d.data ->> 'NGramString') @@ public.mt_grams_query($2) and d.ctid in (select ctid from )));
        : *DEFAULT*
        : some
      Npgsql.PostgresException (0x80004005): 42601: syntax error at or near ")"

Repro

var host = Host.CreateDefaultBuilder()
   .ConfigureServices((ctx, services) =>
    {
        services.AddMarten(opts =>
        {
            opts.Connection(connectionString);
            opts.Schema.For<NGramDoc>()
               .NgramIndex(x => x.NGramString)
               .MultiTenanted();
        })
       .ApplyAllDatabaseChangesOnStartup()
       .UseLightweightSessions();
    })
   .Build();

await using var scope = host.Services.CreateAsyncScope();
var session = scope.ServiceProvider.GetRequiredService<IDocumentSession>();

session.Store(new NGramDoc
{
    SomeList = ["foo", "bar"],
    NGramString = "something searchable"
});
await session.SaveChangesAsync();

var result = await session.Query<NGramDoc>()
   .Where(x => x.NGramString.NgramSearch("some") && x.SomeList.Any(y => y.StartsWith("fo")))
   .ToListAsync();

Console.WriteLine("Results: " + result.Count);

await host.StartAsync();

public class NGramDoc
{
    public Guid Id { get; set; }
    public List<string> SomeList { get; set; } = new();
    public string NGramString { get; set; } = "";
}
@jeremydmiller jeremydmiller added this to the 7.0.0 milestone Jan 21, 2024
@jeremydmiller
Copy link
Member

Fixed locally.

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

No branches or pull requests

2 participants