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

Query language attr cannot filter on the name attribute. #278

Closed
damienmg opened this issue Jul 3, 2015 · 5 comments
Closed

Query language attr cannot filter on the name attribute. #278

damienmg opened this issue Jul 3, 2015 · 5 comments
Assignees
Labels
category: misc > misc P3 We're not considering working on this, but happy to review a PR. (No assignee) type: feature request
Milestone

Comments

@damienmg
Copy link
Contributor

damienmg commented Jul 3, 2015

Repro:
bazel query 'attr("name", ".*", //...)'

Result:
an empty set.

Expected:
All rule target

@damienmg damienmg added type: bug P2 We'll consider working on this in future. (Assignee optional) labels Jul 3, 2015
@laszlocsomor laszlocsomor self-assigned this Jul 6, 2015
@damienmg damienmg added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed P2 We'll consider working on this in future. (Assignee optional) labels Nov 27, 2015
@damienmg damienmg modified the milestone: 1.0 Jun 14, 2016
@buchgr
Copy link
Contributor

buchgr commented Feb 7, 2017

@damienmg @laszlocsomor It seems to work for me with the current master branch.

Running the command on the "Getting Started" example project gives:

buchgr@buchgr0:~/code/build-java$ bazel query 'attr("name", ".*", //...)'
..........
//src/main/java/com/example/cmdline:runner
//:my-runner
//:my-other-runner
//:greeter

Running the command on the bazel code base also seems to work

buchgr@buchgr0:~/code/bazel$ bazel query 'attr("name", ".*", //...)' | wc -l
1249

@buchgr buchgr closed this as completed Feb 7, 2017
@laszlocsomor
Copy link
Contributor

Filtering still doesn't work for me with 0.4.4:

$ ../bazel-0.4.4.exe query '//src:*' | grep "install"
//src:install_base_key_notools
//src:install_base_key-file_notools
//src:install_base_key
//src:install_base_key-file

$ ../bazel-0.4.4.exe query 'attr("name", ".*install.*", "//src:*")'
INFO: Empty results

@laszlocsomor laszlocsomor reopened this Feb 7, 2017
@buchgr
Copy link
Contributor

buchgr commented Feb 7, 2017

@laszlocsomor I can reproduce the bug.Will look...

Also, should bazel query '//src:*' and bazel query 'attr("name", ".*", "//src:*")' be equivalent? I get different result set with 0.4.4.

@laszlocsomor
Copy link
Contributor

They should be different. The first one lists input and output file targets along with rules, the second one should only list rules.

@buchgr
Copy link
Contributor

buchgr commented Feb 8, 2017

It seems like a problem accessing the attribute value - it's always the empty string.

While query 'attr("name", ".*", "//src:*")' works, query 'attr("name", ".+", "//src:*")' does not (.* vs .+ in the pattern).

luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
    The name attribute gets special treatment in the codebase, in that
    it's not simply yet another attribute but stored in it's own field.

    Thus, every callside dealing with attributes needs to be aware of
    this special case and explicitly handle the name attribute. It's
    easy to see that this can lead to bugs. For example, querying for
    the name attribute is currently broken due the querying code not
    being aware of the special case [1].

    Discussions with experienced bazel developers came to the conclusion
    that there is no need (anymore) to treat the name attribute specially
    and thus we decided it's best to remove the special treatment and
    handle the name attribute as any other attribute.

    This change removes the handling of name attributes and also adds a test
    case to verify that bug [1] is fixed.

    [1] bazelbuild/bazel#278

    --
    PiperOrigin-RevId: 147446345
    MOS_MIGRATED_REVID=147446345
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: misc > misc P3 We're not considering working on this, but happy to review a PR. (No assignee) type: feature request
Projects
None yet
Development

No branches or pull requests

3 participants