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

Calling save on a model for which no changes have been made generates invalid sql #1416

Closed
dob9601 opened this issue Jan 21, 2023 · 1 comment

Comments

@dob9601
Copy link

dob9601 commented Jan 21, 2023

Description

Calling save on a model for which no changes have been made generates invalid sql which causes an unclear error message.

Tested against MariaDB, but have reason to believe it should occur with all database backends

This behaviour seems to be originating from within the Update::one() method

Steps to Reproduce

let db = Database::connect("mysql://some_connection_url").await.unwrap();

// UserActive in this case is an alias to an ActiveModel
let user = UserActive { ... }
user.insert(&db).await.unwrap()

// Some quantity of code that may or may not change the user.

let active_user: UserActive = user.into();

active_user.save(&db).await.unwrap();

Expected Behavior

Either a clearer error message stating that the model hasn't changed - thus save cannot be called or no error at all and the call to save to be a no-op

Actual Behavior

Raises:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE `users`.`id` = ?' at line 1"

Reproduces How Often

100%

Versions

MariaDB: Ver 15.1 Distrib 10.9.4-MariaDB, for Linux (x86_64) using readline 5.1
sea-orm: 0.10.5

Additional Information

@tyt2y3
Copy link
Member

tyt2y3 commented Jan 26, 2023

This is a duplicate to #1376

@tyt2y3 tyt2y3 closed this as completed Jan 26, 2023
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

No branches or pull requests

2 participants