BigDecimal is not supported by codegen
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 9.9k
- Forks
- 735
- Avg merge
- 6h 36m
- Merged PRs (30d)
- 8
Description
Description
The auto-generated Model defaults to Decimal which breaks when with-rust_decimal is disabled and with-bigdecimal is enabled.
Also the docs do not list BigDecimal as a valid numeric/decimal type.
https://www.sea-ql.org/SeaORM/docs/generate-entity/entity-structure/#column-type
Steps to Reproduce
I have a postgres table defined with a migration
.col(ColumnDef::new(Table::Column).decimal_len(78, 0))
that works without issue but then when I generate an entity using the sea-orm-cli it generates an invalid Model implementation of
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq)]
pub struct Model {
...
pub column: Decimal,
}
Expected Behavior
Fundamentally I expect it to generate code that compiles, however, I am not sure if the right approach here is to figure out somehow that it should use BigDecimal during codegen or if it should alias BigDecimal as Decimal when only the one feature flag is enabled.
If both feature flags are enabled I think it would be appropriate to default to one or the other and leave it up to the user to manually change them as needed. I would lean towards defaulting to BigDecimal as it is not a default feature flag so having both active implies it is the preference. I don't have particularly strong feelings on this case since I think most people (myself for sure) will decide to use just one or the other exclusively, though, it is not improbable that someone will accidentally not disable the default feature flag.
Actual Behavior
Generated code that does not compile with the chosen feature flags.
Reproduces How Often
Reliably
Workarounds
For now I am just manually replacing all generated Decimal references with BigDecimal.
Reproducible Example
Non-trivial as it requires generating code from a live database.
Versions
postgres 15
├── sea-orm v0.11.0
│ ├── sea-orm-macros v0.11.0 (proc-macro)
│ ├── sea-query v0.28.3
│ │ ├── sea-query-derive v0.3.0 (proc-macro)
│ ├── sea-query-binder v0.3.0
│ │ ├── sea-query v0.28.3 (*)
│ ├── sea-strum v0.23.0
│ │ └── sea-strum_macros v0.23.0 (proc-macro)
├── sea-orm-migration v0.11.0
│ ├── sea-orm v0.11.0 (*)
│ ├── sea-orm-cli v0.11.0
│ │ ├── sea-schema v0.11.0
│ │ │ ├── sea-query v0.28.3 (*)
│ │ │ └── sea-schema-derive v0.1.0 (proc-macro)
│ ├── sea-schema v0.11.0 (*)
├── sea-orm v0.11.0 (*)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the sea-orm-cli code-generation path and the documented column-type page, then reproduce the reported Postgres decimal schema with only the with-bigdecimal feature enabled. Done means the generated Model compiles with the selected feature flags and the documentation lists BigDecimal as a valid numeric or decimal type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgres, rust
- Domain
- databases, documentation, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100