Skip to content

Fix some default column value bugs - #5630

Open
bfops wants to merge 5 commits into
bfops/consolidate-default-testsfrom
bfops/fix-defaults
Open

Fix some default column value bugs#5630
bfops wants to merge 5 commits into
bfops/consolidate-default-testsfrom
bfops/fix-defaults

Conversation

@bfops

@bfops bfops commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Description of Changes

Fixes #5623
Fixes #5624
Fixes #5627
Fixes #5622

API and ABI breaking changes

No. Fixes two build failures.

Expected complexity level and risk

2

Testing

  • Further smoketest cases have been enabled
    • C# modules with f32 values are building successfully

@bfops bfops changed the title Fix two default value bugs Fix some default column value bugs Jul 30, 2026
@bfops bfops linked an issue Jul 30, 2026 that may be closed by this pull request
use spacetimedb::table::TableInternal;
use spacetimedb::AlgebraicValue;

#[spacetimedb::table(accessor = defaults)]

@bfops bfops Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should either

  1. remove this file
  2. extend it to cover all default datatypes

I don't have a strong opinion about which, but I would like the reviewer to have one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the custom_defaults smoketest already test this behavior? With that understanding, I'd like to remove this file and keep the tests in the smoketest.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does in a sense, just a bit less directly; it doesn't check that it gets coerced to the right
AlgebraicValue, but if you think it's close enough to be redundant (or maybe just doesn't matter) then I'm happy to remove this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The smoketest does check that the default value in a newly-inserted row is the same as the declared one, right? I don't see how that test could pass while this one fails.

@bfops
bfops marked this pull request as ready for review July 30, 2026 13:23
@bfops bfops mentioned this pull request Jul 30, 2026
2 tasks
@bfops
bfops requested a review from gefjon July 30, 2026 13:28
Comment on lines 5 to 34
const EXPECTED_DEFAULTS: &[(&str, &str)] = &[
("bool_value", "true"),
("u8_value", "8"),
// TODO: uncomment this once negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5622
//("i8_value", "-8"),
("u16_value", "16"),
// TODO: uncomment this once negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5622
//("i16_value", "-16"),
("u32_value", "32"),
// TODO: uncomment this once negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5622
//("i32_value", "-32"),

// TODO: uncomment once u64s are fixed.
// https://github.com/clockworklabs/SpacetimeDB/issues/5623
//("u64_value", "64"),

("u64_value", "64"),
// TODO: uncomment this once negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5622
//("i64_value", "-64"),

// TODO: uncomment once floats are fixed in C# and f32s are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5624
// https://github.com/clockworklabs/SpacetimeDB/issues/5627
//("f32_positive_value", "32.5"),

// TODO: uncomment once floats are fixed in C#, f32s are fixed in Rust, and negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5624
// https://github.com/clockworklabs/SpacetimeDB/issues/5627
("f32_positive_value", "32.5"),
// TODO: uncomment once negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5622
//("f32_negative_value", "-32.5"),
("f64_positive_value", "64.25"),
// TODO: uncomment once negative defaults are fixed in Rust
// https://github.com/clockworklabs/SpacetimeDB/issues/5622
//("f64_negative_value", "-64.25"),

// TODO: uncomment this once string default values are fixed in Rust
//("string_value", r#""default string""#),
];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I uncommented the negative value tests and ran locally and they passed. I believe the problem with negative values was:

  • #val.serialize(...) expanded to e.g. -32.serialize(...).
  • After macroexpansion, that parsed as - (32.serialize(...)).

You change makes it so that the macro now correctly constructs the negation operator to the integer first, and then converts it into AlgebraicValue, instead of trying to apply the negation operator afterwards.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh fantastic! thank you

use spacetimedb::table::TableInternal;
use spacetimedb::AlgebraicValue;

#[spacetimedb::table(accessor = defaults)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the custom_defaults smoketest already test this behavior? With that understanding, I'd like to remove this file and keep the tests in the smoketest.

@bfops bfops linked an issue Jul 30, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants