Skip to content

Bug: Exception on Merge (PostgreSQL) #776

@not-authorized

Description

@not-authorized

Bug Description

Throws an exception during the merge.

var login = new UserLogin
{
    AccountId = account.Id,
    RefreshToken = refreshToken,
    IssuedUtc = now,
    ExpiresUtc = now.AddMonths(1),
    UserAgent = _userService.UserAgent
};

var fields = Field.Parse<UserLogin>(e => new
{
    e.RefreshToken,
    e.IssuedUtc,
    e.ExpiresUtc
});

return (int)await Connection.MergeAsync(login, qualifiers: p => new { p.UserAgent }, fields: fields);

Exception Message:

RepoDb.Exceptions.InvalidQualifiersException: PostgreSql is using the primary key as qualifier for (INSERT or REPLACE) operation. Consider creating 'PrimaryKey' in the app.user_login and set the 'qualifiers' to NULL.

Schema and Model:

Please share to us the schema of the table (not actual) that could help us replicate the issue if necessary.

CREATE TABLE user_login
(
    id               int generated always as identity,
    account_id       int                            not null,
    refresh_token    varchar(255)                   not null,
    issued_utc       timestamp without time zone    not null,
    expires_utc      timestamp without time zone    not null,
    user_agent       varchar(255)                   null,
    PRIMARY KEY (id),
    FOREIGN KEY (account_id) REFERENCES account (id) ON UPDATE NO ACTION ON DELETE CASCADE
);

And also the model that corresponds the schema.

[Table("user_login", Schema = "app")]
public partial class UserLogin
{
    [Key]
    [Column("id")]
    public int Id { get; set; }
    [Column("account_id")]
    public int AccountId { get; set; }
    [Required]
    [Column("refresh_token")]
    [StringLength(255)]
    public string RefreshToken { get; set; }
    [Column("issued_utc")]
    public DateTime IssuedUtc { get; set; }
    [Column("expires_utc")]
    public DateTime ExpiresUtc { get; set; }
    [Column("user_agent")]
    [StringLength(255)]
    public string UserAgent { get; set; }
    
    [ForeignKey(nameof(AccountId))]
    [InverseProperty("UserLogin")]
    public virtual Account Account { get; set; }
}

Library Version:

Example: RepoDb.PostgreSql v1.1.3

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixedThe bug, issue, incident has been fixed.todoThings to be done in the future

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions