Skip to content

Comments

propagate Clone and PartialEq for DbState#168

Merged
lex148 merged 1 commit intoweldsorm:mainfrom
SilentVoid13:main
Jan 9, 2026
Merged

propagate Clone and PartialEq for DbState#168
lex148 merged 1 commit intoweldsorm:mainfrom
SilentVoid13:main

Conversation

@SilentVoid13
Copy link
Contributor

useful when T is Clone or PartialEq

@lex148
Copy link
Contributor

lex148 commented Jan 9, 2026

I don't know about this one. I have some concerns.

If you are cloning the DbState<Model> then you are going to have two objects, then these two objects are going to get out of sync.

For example:

  let car = Car::find_by_id(42, &conn).await?;
  let same_car = car.clone();

  car.delete(&conn).await?;

  // this will error out because the DbState for this object thinks it is still in the database.
  same_car.save(&conn).await?;

Its kinda like having two mut references to the same underlying piece of data. bad things are going to happen.

If you just want a clone of the data, why not:

  let car: Car = Car::find_by_id(42, &conn).await?.into_inner();
  let same_car: Car = car.clone();

@SilentVoid13
Copy link
Contributor Author

SilentVoid13 commented Jan 9, 2026

hmm thinking about it I think you're right, this is encouraging a bad pattern. Let's just propagate PartialEq.

@lex148 lex148 merged commit 67f014e into weldsorm:main Jan 9, 2026
9 checks passed
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

Successfully merging this pull request may close these issues.

2 participants