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

Don't parse all attributes as Meta #774

Closed
NyxCode opened this issue Oct 28, 2020 · 5 comments · Fixed by #791
Closed

Don't parse all attributes as Meta #774

NyxCode opened this issue Oct 28, 2020 · 5 comments · Fixed by #791

Comments

@NyxCode
Copy link

NyxCode commented Oct 28, 2020

Currently, sqlx parses every field attribute as Meta.
This breaks for every struct which has non-meta attributes with custom syntax. In ormx, for example, I have attributes which may have a path as value, for example: #[ormx(table = crate::models::User)].

When parsing attributes, I suggest we first check if the first token is sqlx, then continue parsing as Meta.

@dragonnn
Copy link
Contributor

dragonnn commented Oct 29, 2020

diff --git a/sqlx-macros/src/derives/attributes.rs b/sqlx-macros/src/derives/attributes.rs
index 3feea50b..4d2dadbb 100644
--- a/sqlx-macros/src/derives/attributes.rs
+++ b/sqlx-macros/src/derives/attributes.rs
@@ -123,13 +123,13 @@ pub fn parse_child_attributes(input: &[Attribute]) -> syn::Result<SqlxChildAttri
     let mut rename = None;
     let mut default = false;
 
-    for attr in input {
+    for attr in input.iter().filter(|a| a.path.is_ident("sqlx")) {
         let meta = attr
             .parse_meta()
             .map_err(|e| syn::Error::new_spanned(attr, e))?;
 
         match meta {
-            Meta::List(list) if list.path.is_ident("sqlx") => {
+            Meta::List(list) => {
                 for value in list.nested.iter() {
                     match value {
                         NestedMeta::Meta(meta) => match meta {

I think something like that should fix that problem, right? I can not test at the moment since I have problem build my project with a local version of sqlx. Complains about that no runtime is enabled (but it is).

@NyxCode
Copy link
Author

NyxCode commented Oct 29, 2020

Yeah, that should do the trick!

@jplatte
Copy link
Contributor

jplatte commented Nov 4, 2020

I wonder what the map_err is there for. Either way, the second check you added it redundant but this should fix the issue 👍

@dragonnn
Copy link
Contributor

dragonnn commented Nov 4, 2020

I removed the second check when you look at the patch. Ok, I will create a PR in a minute :)

@jplatte
Copy link
Contributor

jplatte commented Nov 4, 2020

Oh, right! 😅

To make it easier to read diffs in GitHub comments you can start the codeblock with ```diff 😉

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 a pull request may close this issue.

3 participants