-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add read-only mode that doesn't modify entries #38
base: master
Are you sure you want to change the base?
Conversation
This will also make hasattr on LDAPEntry more predictable in situations where we do not want an empty set returned to add values but rather want to know whether or not the entry has that specific attribute or not.
I kinda want to know the story behind this feature. 😏 |
It's actually not as bad as you're probably imagining! |
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.
Makes sense to me to have this feature. Left two small inline comments.
@@ -337,6 +340,8 @@ def delete(self, entry, recursive=False): | |||
:param recursive: If subentries should be deleted recursively. | |||
:type recursive: bool | |||
""" | |||
if self._read_only: |
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.
This is probably better suited as a decorator, e.g. @check_for_ro
.
@@ -29,3 +29,6 @@ class LDAPAttributeNameNotFoundError(LDAPomError): | |||
|
|||
class LDAPCouldNotFetchAttributeTypes(LDAPomError): | |||
pass | |||
|
|||
class LDAPomReadOnlyError(LDAPomError): |
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.
As only the base error uses LDAPom
, I would skip the om
in the class name here.
This behavior is only for multi-value attributes. I think back then we were unsure about how to represent "zero entries in this multi-value attribute" and we chose the empty set (rather than AttributeError) because it made sense to us in this context. An empty list is not written back to the server either (see Instead of using |
Sure in theory I could change it in the scripts, but correct me if I'm wrong, but the way I see it I would then need to pay attention to which attributes I'm checking. |
Hm, I agree, that sucks. I'm not against a read only mode, it might be useful in some situations as a protection against programming mistakes modifying things, but changing how attribute value retrieval works in a subtle way in just this mode sounds weird to me. Changing the behavior in the general case would be a bigger task and would also result in weird behavior. Remove a bunch of values from a list, poof, Maybe we could add a util method to the attribute class? Maybe |
This will also make hasattr on LDAPEntry more predictable in situations
where we do not want an empty set returned to add values but rather want
to know whether or not the entry has that specific attribute or not.