-
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
Move the Comment
class to the new backend interface
#2225
Move the Comment
class to the new backend interface
#2225
Conversation
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.
Do we have any tests? It looks like your Comment
class was abstract but this doesn't seem to have been caught. Maybe everywhere in the code is still uses backend.comments.
...if so these should be changed to Comment
.
aiida/orm/comments.py
Outdated
""" | ||
return self._backend_entity.is_stored() | ||
|
||
@abc.abstractproperty |
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.
@abc.abstractproperty |
aiida/orm/comments.py
Outdated
|
||
@abc.abstractproperty | ||
def uuid(self): | ||
pass |
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.
pass | |
return self._backend_entity.uuid |
aiida/orm/comments.py
Outdated
|
||
@abc.abstractmethod | ||
def get_ctime(self): | ||
pass |
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.
pass | |
return self._backend_entity.get_ctime() |
aiida/orm/comments.py
Outdated
|
||
@abc.abstractmethod | ||
def get_user(self): | ||
pass |
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.
pass | |
return users.User.from_backend_entity(self._backend_entity.get_user()) |
aiida/orm/comments.py
Outdated
|
||
@abc.abstractmethod | ||
def set_user(self, value): | ||
pass |
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.
pass | |
self._backend_entity.set_user(value.backend_entity) |
|
||
def get_ctime(self): | ||
return self.dbcomment.ctime | ||
return self._dbmodel.ctime | ||
|
||
def set_ctime(self, val): |
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.
See comment above about ctime
""" | ||
super(SqlaComment, self).__init__(backend) | ||
type_check(user, users.SqlaUser) | ||
self._dbmodel = utils.ModelWrapper(DbComment(node=node.dbnode, user=user.dbmodel, content=content)) | ||
|
||
@property | ||
def pk(self): |
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.
Delete (in superclass)
|
||
@property | ||
def pk(self): | ||
return self.dbcomment.id | ||
return self._dbmodel.pk | ||
|
||
@property | ||
def id(self): |
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.
Delete (in superclass)
|
||
@property | ||
def to_be_stored(self): | ||
return self.dbcomment.id is None | ||
def stored(self): |
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.
-> is_stored()
|
||
def get_ctime(self): | ||
return self.dbcomment.ctime | ||
return self._dbmodel.ctime | ||
|
||
def set_ctime(self, val): |
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.
consider deleting
The only "tests" that were in place are indirect through the |
Quick comment - I was just wondering if we need an entity also for comments (and similarly for links) or these can just be considered as a "property" of Node (even if in our implementation they live in a different DB table). Because then intuitively if it's an entity one would expect to be able to "join" them via the query builder. Of course since this implemented it's fine to keep as it is, I point out this just for discussion and to decide what to do with the other tables that do not have a corresponding entity (notably links but maybe something else?) |
Good point @giovannipizzi , so long as the interface is clear (i.e. the comment interaction is properly defined through the |
At the current stage having it as a separate full-fledged entity seems a bit overkill, agree, but I can easily imagine that when we do start to use it, it will be very useful to have it queryable. As I understand its original intention, it is for users to comment on certain nodes, i.e. in a discussion on a platform like MaterialsCloud or just when sharing nodes. For this use case, being able to find all nodes on which a particular user has commented, would be useful. Should we leave it like this for now and I just add tests for the ORM classes? |
Yes, leave it as is. Some testing is good but for now I reckon a 'system testing' approach is fine i.e. just rely on higher level functions like the verdi command line tests to put it through its paces. |
Ok for me.
rather
even if maybe it makes the QB code more complex. I'm open to suggestions. |
ea4cc22
to
10eda70
Compare
I added support for querying |
7e9c96e
to
64ad5e1
Compare
self.dbcomment.save() | ||
def set_mtime(self, value): | ||
self._dbmodel.mtime = value | ||
if self.is_stored: |
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 not needed. The ModelWrapper
does this for all attributes anyway. Sorry I missed it the first time.
self.dbcomment.save() | ||
def set_user(self, value): | ||
self._dbmodel.user = value | ||
if self.is_stored: |
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.
Not needed
def store(self): | ||
"""Can only store if both the node and user are stored as well.""" | ||
if self._dbmodel.dbnode.id is None or self._dbmodel.user.id is None: | ||
raise exceptions.ModificationNotAllowed |
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.
raise exceptions.ModificationNotAllowed | |
raise exceptions.ModificationNotAllowed('The corresponding node and/or user are not stored') |
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.
Balls, you're breaking 'em
"""Can only store if both the node and user are stored as well.""" | ||
if self._dbmodel.dbnode.id is None or self._dbmodel.user.id is None: | ||
self._dbmodel.dbnode = None | ||
raise exceptions.ModificationNotAllowed |
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.
raise exceptions.ModificationNotAllowed | |
raise exceptions.ModificationNotAllowed('The corresponding node and/or user are not stored') |
aiida/orm/__init__.py
Outdated
calculation.__all__ + | ||
comments.__all__ + |
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.
comments.__all__ + |
64ad5e1
to
ff09cde
Compare
def store(self): | ||
"""Can only store if both the node and user are stored as well.""" | ||
if self._dbmodel.dbnode.id is None or self._dbmodel.user.id is None: | ||
raise exceptions.ModificationNotAllowed |
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.
Balls, you're breaking 'em
This allows to make the methods of `Node` backend independent and as a result makes the implementation a lot simpler. The command line interface is also adapted and simplified.
ff09cde
to
f5406dd
Compare
Fixes #2223