Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: General("List should not be empty") when using SELECT, INSERT is fine #282

Closed
ernestas-poskus opened this issue Aug 30, 2019 · 3 comments

Comments

@ernestas-poskus
Copy link
Contributor

Have a problem with nested UDT SELECT query (INSERT is fine, verified data with cqlsh shell).

I use scylla database.

From backtrace looks like this place panics

macro_rules! list_as_rust {
    ($($into_type:tt)+) => (
        impl AsRustType<Vec<$($into_type)+>> for List {
            fn as_rust_type(&self) -> Result<Option<Vec<$($into_type)+>>> {
                match self.metadata.value {
                    Some(ColTypeOptionValue::CList(ref type_option)) |
                    Some(ColTypeOptionValue::CSet(ref type_option)) => {
                        let type_option_ref = type_option.as_ref();
                        let convert = self
                            .map(|bytes| {
                                as_rust_type!(type_option_ref, bytes, $($into_type)+)
                                    .unwrap()
                                    // item in a list supposed to be a non-null value.
                                    // TODO: check if it's true
                                    .unwrap()
                            });

                        Ok(Some(convert))
                    },
                    _ => Err(Error::General(format!("Invalid conversion. \
                            Cannot convert {:?} into List (valid types: List, Set).",
                            self.metadata.value)))
                }
            }
        }
    );
}
                                as_rust_type!(type_option_ref, bytes, $($into_type)+)
                                    .unwrap()
                                    // item in a list supposed to be a non-null value.
                                    // TODO: check if it's true
                                    .unwrap()

.unwrap in particular. Although I don't insert empty list (Vec) I assume it should initialize empty Vec on Rust side or did I misunderstood something?

@AlexPikalov
Copy link
Owner

AlexPikalov commented Aug 30, 2019

Hi @ernestas-poskus ,

Thanks for submitting the issue!
If you don't submit an empty list I assume that there will be value NotSet returned by a server. Thus https://github.com/AlexPikalov/cdrs-helpers-derive/blob/master/src/common.rs#L74 will be not Ok.

If there is a case for you that for a some value no-value can be submitted you can try to have Option<Vec<YourType>> as a type for this field instead of Vec. CDRS should tackle it and there shouldn't be any panic. IMO it describes your data nature more precisely, you'll just get None. I believe that such sort of result interpretation as None -> vec![] should be on the application side, not on a driver.

Please let me know if it makes sense to you

@ernestas-poskus
Copy link
Contributor Author

Thank you for reply, value is not empty and I read instantly after write.. Anyway seems like it was Scylla issue after updating to latest docker version everything works as expected 🤷‍♂️.

Seems like an issue was with UDT TYPE, columns in nested UDT TYPE, Scylla cutoff last 2 columns, therefore, SELECT was failing although INSERT was successful.

Thanks for help 🙇‍♂️.

Please include patreon link or sth, I would like to buy you a beer 🍺.

@AlexPikalov
Copy link
Owner

@ernestas-poskus
Glad to know it's working know. It's my pleasure to help 🙂
PS: will consider adding Patreon 😄

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

No branches or pull requests

2 participants