-
Notifications
You must be signed in to change notification settings - Fork 192
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
✨ NEW: Add orm.Entity.fields
interface for QueryBuilder
(cont.)
#6245
Conversation
@sphuber Opened! Had to fix a few |
Are you sure? From what I can see, most if not all are related to changes in this PR. Note that a warning can occur at a line that was not actually touched, but it uses a variable or calls a method that was. Since it checks for type consistency, if any type elsewhere was changed but the affected line wasn't, this can cause mypy to raise a warning. As for why this didn't crop up in the original PR: the original PR was over 2 years old and back then we had an older version of mypy and had less strict type checking enabled. So this does not surprise me at all that we find new problems. |
Okay. No problem. I'll dig deeper and resolve these issues 👍 Dug just slightly deeper...
How would your argument pertain to this error? Importing Answering my own question, at least for the the |
One more thing... The
This was added by Chris in #6071. What's happening here? |
This is because you don't have the optional dependency |
That is exactly why it is running as a local module, because it needs all the dependencies. When developing, you should install with at least |
@sphuber I think perhaps my environment is not set up correctly? I checked out |
That indeed suggests your environment is not properly set up. I just ran What OS are you on, and how did you create your env? And how are you running pre-commit? |
Windows -> WSL2 ->
I was suspecting a collision of packages, so I uninstalled python, pip, and conda entirely, then reinstalled conda/mamba via miniforge. I recreated the environment and ran the above code block. I get Not sure what's going on. In the spirit of moving this along, gonna try running this in a container. |
Hmm, that is weird. But for typing, a lot changed in Python 3.10 and that is what our CI is using. Could you try in an env with Python 3.10 or newer? |
Tested with 3.10 and 3.12. Same issue. Consider the following:
In In Do you expect |
I see what the problem is. I think the |
Maybe 🤷🏻♂️ |
510fd52
to
5a99d36
Compare
Either way, it is not relevant ultimately. The pre-commit on this PR is failing for genuine reasons with errors due to code introduced in the PR. Simply address those and then when you commit, your pre-commit should pass. |
Sorry 😅 The whole point of my original comment regarding In the end, I was able to "calm" I was referencing the Thanks for the help @sphuber See issue #5026 - running |
5a99d36
to
b198dfe
Compare
Okay, |
One thing that is apparently missing is You can write qb = QueryBuilder().append(
Data,
filters={
"pk": 5,
"label": "hello"
}
) as qb = QueryBuilder().append(
Data,
filters={
Data.fields.pk: 5,
Data.fields.label: "hello"
}
) or, using comparators, as qb = QueryBuilder().append(
Data,
filters=(Data.fields.pk == 5) & (Data.fields.label == "hello")
) Also, filters = (Data.fields.pk > 5) & (Data.fields.pk < 10) is correctly translated into and However, I don't see a way you do qb = QueryBuilder().append(
Data,
filters={
"or": [
{"pk": 5},
{"label": "hello"}
]
}
) is not available through something like (Data.fields.pk == 5) | (Data.fields.label == "hello") Considering implementing it |
Absolutely no problem, but maybe add me as a co-author in the final merge commit 😉: https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors
|
Duh 👍 |
3f72029
to
1610ec0
Compare
@sphuber, @chrisjsewell I tested the
Anyhow, I rebases my work onto your branch and proceeded to work out model inheritance automation. Consider the following: class EntityChild(Entity, metaclass=EntityFieldMeta):
class Model:
attr: str = 'some_attr' Note that
This is due to the particular means in which I am constructing the class EntityChild(Entity, metaclass=EntityFieldMeta):
class Model(BaseModel):
attr: str = 'some_attr' but then we're back to requiring at least one base, and by extension, a check that the base is present. Not ideal 😕 Another concern is that the above leads to the following MRO: Entity.Model.mro()
[abc.Model,
aiida.orm.entities.Entity.Model,
pydantic.main.BaseModel,
object] It gets worse down the inheritance chain, with ProcessNode.Model.mro()
[abc.Model,
aiida.orm.nodes.process.process.ProcessNode.Model,
aiida.orm.utils.mixins.Sealable.Model,
abc.Model,
aiida.orm.nodes.node.Node.Model,
abc.Model,
aiida.orm.entities.Entity.Model,
pydantic.main.BaseModel,
object] Again, everything appears to be working 🤷🏻♂️ But suspect nonetheless! Feels like there's a "correct" approach that I'm just short of hitting. Could use another set of eyes on this. |
This was already fixed, but probably pushed after you had rebased.
Very nice. There is one thing that came to mind. During experimenting, I realized that sometimes a user may actually want to change inheritance on purpose. I don't have a concrete use case yet, but I wondered if it would be feasible, and if this approach (which would effectively prohibit it) would be too restrictive. In any case, this feature would not be used a whole lot (how many However,
This seems to be just the knock-on effect of what you describe later where the dynamically created classes have duplicate base classes. This means the second time a base class is resolved, it redefines I think then that solving the duplicate base models, will fix this warning. Would it not be possible to simply change
Not sure if these |
f6de54a
to
b2c7896
Compare
b2c7896
to
4b03bae
Compare
4b03bae
to
463ae11
Compare
463ae11
to
bbb786a
Compare
@sphuber give it a look. I'll update the docs on approval. UpdateI see there are issues here with Docker. I take it this is due to the issue you mentioned with my |
Looks very similar. Just the |
I'm already on |
Then you're up slack-alley 😅 Probably want to update the |
Yeah, I don't see how either, but considering your PR is passing, as did Jason's fix, I'm concerned something in PR is clashing. UpdateSee #6303 (comment) |
@sphuber may I proceed to document the changes to finalize this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @edan-bainglass last few changes are all good. Just missed some things in the docs. If you can correct those and then squash all your changes in a single commit with a comprehensive commit message, we can merge this PR. Thanks a lot for all the effort!
Thanks @sphuber. Waited for the green light before updating the docs. Will update in the morning. Thanks again 🙏 |
e6294b4
to
16d2c48
Compare
This commit first ensures that all query operations are supported in the new syntax, including negation. The commit also separates the operations by field type via subclassing. It introduces a uniform `orm.fields.add_field` API as an abstraction of the type-dependent allocation of `orm.fields.QbField` flavors. A distinction is made in the API between database columns and attribute fields via the `is_attribute` parameter. If set to `True` (the default), the field is considered an attribute field and as such, `QbField().backend_key` will return `'attribute.key'` in accordance with the `QueryBuilder` mechanics. Note that _only_ in the case of attribute fields, `backend_key` may be aliased via the `alias` parameter. This is done to avoid restrictions on database field naming while maintaining a pythonic interface in the frontend via the `key` parameter, which is validated as pythonic (supporting dot notation).
16d2c48
to
6dd8eca
Compare
@sphuber I believe all is good now. On merge, please add an acknowledgement for @chrisjsewell work 🙂 |
The first commit is still his right? I am planning to simply rebase merge, so the commits will remain attributed to Chris and yourself, respectively. |
Cheers guys! |
@sphuber I neglected to comment on the backend mapping in the commit message ((and sufficiently document the feature). Follow up PR 🤷🏻♂️ |
This PR (created following the suggestion of @sphuber) picks up the work of @chrisjsewell on PR #5088. The PR has been rebased onto
main
as of 11.03.2024.The goal is to resolve any pending issues and concerns, then merge into
main
.See full discussion at #5088.
Currently, all tests pass. Post-tests teardown errors are ignored for now (see comments on #5088 and #6134).
Update
Attempts to consolidate the logic of #6255 with this PR have hit a snag (see discussion below). Planning to merge this PR as is and address #6255 at a later time.