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

Bug: Upsert does not create a new record. #151

Open
2 tasks done
AdaptGit opened this issue Nov 22, 2024 · 2 comments
Open
2 tasks done

Bug: Upsert does not create a new record. #151

AdaptGit opened this issue Nov 22, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@AdaptGit
Copy link

Describe the bug

Upsert does not create a new record in the database and returns null in c#

When using the create statement the record is created and can be seen in surealist. however not the same for upsert, this use to work in previous versions.

The upsert command does work when the item is created

Steps to reproduce

create a library and create a new model and use the upsert commany

`
var surrealDbClient = new SurrealDbClient(SurrealDbOptions.Create()
.WithEndpoint("ws://127.0.0.1:8000/rpc")
.WithNamespace("test")
.WithDatabase("test")
.WithUsername("root")
.WithPassword("root")
.Build());

        RecordId rid = ("person", "john");

        var model = new MyModel { Name = "John", Age = 25, Id = rid };

        var UpsertResult = await surrealDbClient.Upsert(model);
        var createResult = await surrealDbClient.Create(model);

        Assert.IsTrue(createResult != null);
        Assert.IsTrue(UpsertResult != null);

`

The last return false and test case fails.

Screenshot 2024-11-22 at 10 43 37 PM

Expected behaviour

a record should be created and should not be null. this also should be seen in surreallist.

SurrealDB version

Running 2.1.0 for macos on aarch64

Package version(s)

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@AdaptGit AdaptGit added the bug Something isn't working label Nov 22, 2024
@Odonno
Copy link
Contributor

Odonno commented Nov 23, 2024

I made a console app example that resemble the example you provided. Here are some details:

  • using SurrealDb.Net v0.6.0
  • running surrealdb v2.1.0, I did not reproduce this issue
  • .NET 8.0

And here is the source code:

var options = SurrealDbOptions.Create()
    .WithEndpoint("ws://127.0.0.1:8000/rpc")
    .WithNamespace("examples")
    .WithDatabase("console")
    .WithUsername("root")
    .WithPassword("root")
    .Build();

using var db = new SurrealDbClient(options);

const string TABLE = "person";

RecordId rid = (TABLE, "john");

var model = new MyModel
{
    Name = "John",
    Age = 25,
    Id = rid
};

var upsertResult = await db.Upsert(model);
var createResult = await db.Create(model);

Console.ReadLine();

public class MyModel : Record
{
    public string? Name { get; set; }
    public int Age { get; set; }
}

The Upsert works as expected and the Create fails as expected since a record already exist, due to the previous upsert.

If you still experience this issue, can you create a repository with a .NET example project that should reproduce this issue?

@AdaptGit
Copy link
Author

Hi @Odonno

yeah i was able to recreate this issue with .net example from surrealdb. i found that if i use surrealdboption to construct a connection string the upsert fails to create in the database. please see below my examples. i tried on two different computers because i thought my surrealdb was setup incorrectly.

I change these lines of code.
`//var db = new SurrealDbClient("ws://127.0.0.1:8000/rpc");

var db = new SurrealDbClient(
SurrealDbOptions
.Create()
.WithEndpoint("ws://127.0.0.1:8000/rpc")
.WithNamespace("examples")
.WithDatabase("console")
.WithUsername("root")
.WithPassword("root")
.Build()
);

// await db.SignIn(new RootAuth { Username = "root", Password = "root" });
// await db.Use("examples", "console");`

Below is the screenshot of the code in the console you will notice there is no output from the json string because its null.

Screenshot 2024-11-24 at 8 40 18 PM

@AdaptGit AdaptGit reopened this Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants