-
Notifications
You must be signed in to change notification settings - Fork 8
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
rename the annotations attribute #24
base: master
Are you sure you want to change the base?
Conversation
I am not a fan of the implicit migration, especially at creation time. I don't like read-only transactions that suddenly become read-write without my knowledge. And in my case, they won't work anyway: an HTTP I also don't want to rename the attribute. I have millions of objects with annotations. I don't want to rewrite my database for the hypothetical situation that I don't think that a notification hook at this level is appropriate. It seems very far out of scope for this issue in particular, and I support the minimum change to make sure we're using the instance |
The check to detect the need for migration is incomplete. Currently, I think the best approach looks as follows: |
I disagree. All that a non-BTree annotation means is that the BTrees package wasn't available when the annotation was created. There's no requirement for it to be a BTree, and there are uses of persistence outside of ZODB. |
Jason Madden wrote at 2024-12-10 06:02 -0800:
I am not a fan of the implicit migration, especially at creation time.
I see an easy possibility to delay the migration until the annotations
are changed. This would avoid new write transactions.
|
We now check whether it comes from the instance dict or a slot
The PR now tries an alternative approach to distinguish the cases "annotations from class" and "__annotations from instance": it directly checks the instance. Potentially, the check is sufficiently fast to be used also without renaming the attribute. |
I am also not a big fan of renaming the attribute. If we have a way without this I'd prefer it. |
Michael Howitz wrote at 2024-12-13 09:25 -0800:
I am also not a big fan of renaming the attribute. If we have a way without this I'd prefer it.
The PR is based on a test "can we trust an existing obj.__annotations__`.
If it gives true, it migrates.
We can use a similar test "annotations invalid" instead in the
access methods and avoid the migration.
|
@@ -30,16 +31,22 @@ | |||
|
|||
_EMPTY_STORAGE = _STORAGE() | |||
|
|||
ATTR = "_zope_annotations" |
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.
Can we have this as a class attribute?
That would make it easier to come up with a customized adapter that uses another value.
I am BTW not sure this is a use case for anybody :)
Alessandro Pisa wrote at 2024-12-14 00:44 -0800:
@ale-rt commented on this pull request.
> @@ -30,16 +31,22 @@
+ATTR = "_zope_annotations"
Can we have this as a class attribute?
That would make it easier to come up with a customized adapter that uses another value.
Sure. But why would one want to use a specific name?
Apparently, there is a strong wish to keep the
current attribute name `__annoatations__` (to avoid a migration).
Therefore, this PR will likely not get merged.
|
Fixes #15.
attribute.AttributeAnnotations
currently stores the annotations of an object in the attribute__annotations__
. This may conflict with Python's special attribute__annotations__
, e.g. used for type hints.The PR renames
__annotations__
to_zope_annotations
, provides migration code (at least for the simple cases not involving slots) and introduces an optional callbacknotify_object_changed
to inform an interested observer (e.g.plone.protect
) about changes to the object.