Skip to content

Conversation

@jayvdb
Copy link
Collaborator

@jayvdb jayvdb commented Apr 8, 2025

Closes #150

IGNORE PR ATM - it can only be used to show the problem by running

cargo test -p butane --no-default-features --features sqlite,async,async-adapter

@jayvdb jayvdb changed the title Update test to use feature gated field Feature gated struct fields Apr 8, 2025
@jayvdb jayvdb force-pushed the feature-gated-struct-members branch from c04f1c7 to 5d9a571 Compare April 8, 2025 21:31
@jayvdb jayvdb force-pushed the feature-gated-struct-members branch from 5c1af39 to 295a230 Compare April 8, 2025 23:03
@jayvdb jayvdb force-pushed the feature-gated-struct-members branch from 295a230 to c8d05f4 Compare April 8, 2025 23:06
Comment on lines +49 to +52
if name == *"pub_time" {
// Temporary solution to skip pub_time field in butane tests
continue;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is causing the CI failure when running with the datetime feature enabled.

As this macro is being run with the cfg's not evaluated and thus fields removed, the .table files contain all of the fields, causing a mismatch with the ORM objects.

I think we need to extract the cfgs, and evaluate them explicitly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It looks like there isnt any built in Rust support for this. c.f. rust-lang/rust#90765

Maybe a crate which can help...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

CARGO_CFG_FEATURE is only available in build.rs , so this approach would require that there is a build.rs, and it saves CARGO_CFG_FEATURE somewhere so that the migration code can know which features will be active during compilation.

Copy link
Collaborator Author

@jayvdb jayvdb Apr 12, 2025

Choose a reason for hiding this comment

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

An alternative is to add a "cfg attributes" member to AColumn , so that the .table files describe the fact that some columns are conditional based on features.

This sounds more sensible, as then the .table file doesnt change based on which features are enabled.

However this will have some strange effects on migrations.

If a migration is created with a feature gated field enabled, and then compile without that feature, butane will be wanting to create a new migration to remove the field. While migration creation is an explicit user action, it may have been months since they created the feature gated field, and may not realise why the migration is trying to delete a field.

I am thinking we might want to put the active feature list on disk under .butane, and then warn users if they try to generate a migration using a different feature set.

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.

Cfg Attributes on Model Fields Not Properly Handled

1 participant