diesel-rs/diesel

Serials keep incrementing despite begin_test_transaction

SmartMonkey-git opened this issue · 3 comments

Setup

Versions

  • Rust: rustc 1.74.1 (a28077b28 2023-12-04)
  • Diesel: 2.1.0 and diesel_async: 0.4.1
  • Database: Postgres 15.3
  • Operating System MacOs Sonoma 14.0

Feature Flags

  • diesel: diesel_async

Problem Description

Serial columns keep incrementing between test runs despite begin_test_transaction.

What are you trying to accomplish?

I'm trying to run a test in succession, that asserts the value of a serial column.

What is the expected output?

Every time I run this test, I get the same value for that column.

What is the actual output?

The value increments with every run of the test.

Are you seeing any additional errors?

No.

Steps to reproduce

  • Establish connection to DB
  • Run begin_test_transaction
  • Insert a new instance into a table with a serial column
  • Assert the value of said column
  • Run the test again

Checklist

  • [ x ] This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • This issue can be reproduced without requiring a third party crate

Can you explain:

  • Why you believe that is an issue in diesel?
  • Why you believe that this would be the expected behavior?

Hey @weiznich,

Why you believe that is an issue in diesel?

I believe that in a progressed test suite this can lead to problems, where earlier tests leave these changes in the db.

Why you believe that this would be the expected behavior?

Because, I would expect the database to be in the same state as if I would relaunch it.

Thank you for your fast answer! It was unexpected.

Closed as expected behavior as this is just how postgres handles sequences while rolling back transactions: https://www.postgresql.org/docs/current/functions-sequence.html