Skip to content

add TryGetableArray to DeriveValueType macros#2972

Open
sinder38 wants to merge 7 commits into
SeaQL:masterfrom
sinder38:master
Open

add TryGetableArray to DeriveValueType macros#2972
sinder38 wants to merge 7 commits into
SeaQL:masterfrom
sinder38:master

Conversation

@sinder38

@sinder38 sinder38 commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

PR Info

Bug Fixes

  • Allow User wrapped types to be used in Vec inside FromQueryResult structs

Breaking Changes

if users implemented TryGetableArray manually it will require removal

Changes

Adds missing implementation to macros

@sinder38

sinder38 commented Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

umm, why is this even allowed?
this is quite confusing.

#[derive(Clone, Debug, PartialEq, Eq, DeriveValueType)]
pub struct StringVec(pub Vec<String>);

error[E0277]: the trait bound `Vec<Vec<std::string::String>>: TryGetable` is not satisfied
  --> tests/common/features/value_type.rs:72:39
   |
72 | #[derive(Clone, Debug, PartialEq, Eq, DeriveValueType)]
   |                                       ^^^^^^^^^^^^^^^ the trait `TryGetable` is not implemented for `Vec<Vec<std::string::String>>`
   |
   = help: the following other types implement trait `TryGetable`:
             Vec<Braced>
             Vec<Hyphenated>
             Vec<JsonValue>
             Vec<NaiveDate>
             Vec<NaiveDateTime>
             Vec<NaiveTime>
             Vec<OffsetDateTime>
             Vec<PrimitiveDateTime>
           and 21 others
   = note: this error originates in the derive macro `DeriveValueType` (in Nightly builds, run with -Z macro-backtrace for more info)

There seems to be 2 ways to solve this:

  1. To add more implementations that would cover all cases
    Also I should mention that PostgreSQL supports up to 6 dimensions of arrays, even though I dought anyone nests more than 3

  2. It is possible to handle this by not implementing TryGetableArray for types that have Vec inside of them but I think it is bad and confusing. Probably the best way for this option would be to allow user to mark Vec types with something like #[sea_orm(as_pg_array)].

@Huliiiiii Huliiiiii requested a review from tyt2y3 February 27, 2026 13:03
@sinder38

sinder38 commented Feb 27, 2026

Copy link
Copy Markdown
Contributor Author

why not ready

This is not ready to be merged, I handled only DeriveValueTypeStruct and didn't change DeriveValueTypeString.

My reasoning behind it is that I don't fully understand the design goal yet, it could be either:

  • "interpret strings in the dB as this complex type"
  • "use this convenient wrapper to handle underlying dB type as string".

most likely the first one.

@sinder38 sinder38 marked this pull request as draft February 27, 2026 13:11
@sinder38

sinder38 commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

Marking this PR as non-draft even though it is not ready to get active feedback...

@sinder38 sinder38 marked this pull request as ready for review March 9, 2026 03:33
@tyt2y3

tyt2y3 commented Mar 10, 2026

Copy link
Copy Markdown
Member

It is possible to handle this by not implementing TryGetableArray for types that have Vec inside of them
seems like this is a sensible way

Add a new derive attribute `no_vec_impl` to explicitly omit `sea_orm::TryGetableArray`
allow absurd_extreme_comparisons
@sinder38

Copy link
Copy Markdown
Contributor Author

I determite whether to omit TryGetableArray implementation automatically using this:
https://github.com/SeaQL/sea-orm/pull/2972/changes#diff-30cac0d1ada3283259a6839cee56f20544324fabfc5b276387ab14d66cfad16eR157

Increase this once you decide to support dimensionality bigger than 1-2

// Dimensionality 2, which is unsupported
#[derive(FromQueryResult)]
pub struct Row {
    pub matrix: Vec<Vec<i32>> 
}

On separate note, I noticed that test and documentation don't handle array_type.
This:

#[derive(Clone, Debug, PartialEq, Eq, DeriveValueType)]
#[sea_orm(array_type="String")]
pub struct StringVecNoImpl(pub Vec<String>);

@sinder38

Copy link
Copy Markdown
Contributor Author

Any plans to merge?

@sinder38

Copy link
Copy Markdown
Contributor Author

@Huliiiiii, this is a frustrating bug for me. Please tell what else does the core team want for this to get merged?

Comment thread sea-orm-macros/src/derives/value_type.rs Outdated

/// Determines whether to omit `sea_orm::TryGetableArray` implementation for a given field type
/// based on the vector dimensionality.
pub fn omit_vec_impl(field_type: &str) -> bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be pub(crate)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Doesn't have to since it used in one place only right now(honestly, don't remember if it can be used in more places).

column_type: TokenStream,
array_type: TokenStream,
/// Do not implement `sea_orm::TryGetableArray` for this type. Default: false.
no_vec_impl: bool,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you think of the name skip_try_getable_array_impl?
@tyt2y3

Comment thread sea-orm-macros/src/derives/value_type_match.rs

@tyt2y3 tyt2y3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thank you for the contribution.
I think I'd like the behaviour to be opt-in instead of opt-out.
so may be #[sea_orm(try_getable_array)] and support it for both the tuple-struct path and the value_type = "String" path?

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.

DeriveEntityModel types don't implement TryGetable trait when wrapped in a Vec

3 participants