-
Notifications
You must be signed in to change notification settings - Fork 80
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
Basefix #67
Basefix #67
Conversation
@@ -80,7 +80,7 @@ def __init__(self, id_): | |||
self._id = id_ | |||
|
|||
def __eq__(self, other): | |||
return other._id == self._id | |||
return other._id == self._id and type(self) == type(other) |
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.
doesn't _id
equality imply they're the same?
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.
Nope, accidentally compared a RawData object and PreprocessedData object with the same id and they were considered equal. Need the type check. It's because this is in the base class I think.
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.
since _id
isn't globally unique then, how confident are you that create
and delete
work as expected?
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.
What do you mean by that? Create and delete are defined by each child object, so they should work regardless of this issue. This is more for comparison after creation.
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.
it looks like, right now, you can delete something of type foo using an instance of type bar. is that intended?
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.
Scratch that, you pass an ID of the thing you want to delete as a class method. You can't delete foo with bar thing because of this. All you are using is the integer id.
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.
Should we change delete to be instance method instead of a class method? This will solve this issue.
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 way, de delete functions won't need to get an id, they will get them from the instance.
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.
that seems reasonable, is there a need to pass an _id
to delete
?
On Mon, Jun 2, 2014 at 12:06 PM, josenavas notifications@github.com wrote:
In qiita_db/base.py:
@@ -80,7 +80,7 @@ def init(self, id_):
self.id = iddef __eq__(self, other):
return other._id == self._id
return other._id == self._id and type(self) == type(other)
This way, de delete functions won't need to get an id, they will get them
from the instance.—
Reply to this email directly or view it on GitHub
https://github.com/biocore/qiita/pull/67/files#r13298288.
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.
When it was a class method it needed an id. I won't be needed once it is an
instance method.
2014-06-02 12:13 GMT-06:00 Daniel McDonald notifications@github.com:
In qiita_db/base.py:
@@ -80,7 +80,7 @@ def init(self, id_):
self.id = iddef __eq__(self, other):
return other._id == self._id
return other._id == self._id and type(self) == type(other)
that seems reasonable, is there a need to pass an
_id
todelete
?
… <#1465dc9952698c34_>
On Mon, Jun 2, 2014 at 12:06 PM, josenavas notifications@github.com
wrote: In qiita_db/base.py: > @@ -80,7 +80,7 @@ def init(self, id_): >
self.id = id > > def eq(self, other): > - return other._id ==
self._id > + return other._id == self._id and type(self) == type(other)
This way, de delete functions won't need to get an id, they will get them
from the instance. — Reply to this email directly or view it on GitHub <
https://github.com/biocore/qiita/pull/67/files#r13298288>.—
Reply to this email directly or view it on GitHub
https://github.com/biocore/qiita/pull/67/files#r13298667.
Jose Navas
👍 Good catch on the @wasade if you don't see any further issues, feel free to merge it |
@@ -80,7 +80,7 @@ def __init__(self, id_): | |||
self._id = id_ | |||
|
|||
def __eq__(self, other): | |||
return other._id == self._id |
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.
My suggestion here is that we separate checks one per if statement. This is very helpful for debugging.
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.
I don't see this point... it will return true or false anyways, you're not going to know in which if statement it was providing the output.
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.
Yes, but if you add a print statement inside the if conditional then you
can quickly check that as opposed to having to break the contitional at
the botton in mutliple lines.
On (Jun-02-14|10:37), josenavas wrote:
@@ -80,7 +80,7 @@ def init(self, id_):
self.id = iddef __eq__(self, other):
return other._id == self._id
I don't see this point... it will return true or false anyways, you're not going to know in which if statement it was providing the output.
Reply to this email directly or view it on GitHub:
https://github.com/biocore/qiita/pull/67/files#r13296674
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.
adds clarity in the traceback as well
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.
Oh, ok, thanks!
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.
OK, broken up.
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!
On (Jun-02-14|11:10), Joshua Shorenstein wrote:
@@ -80,7 +80,7 @@ def init(self, id_):
self.id = iddef __eq__(self, other):
return other._id == self._id
OK, broken up.
Reply to this email directly or view it on GitHub:
https://github.com/biocore/qiita/pull/67/files#r13298524
@@ -80,7 +80,10 @@ def __init__(self, id_): | |||
self._id = id_ | |||
|
|||
def __eq__(self, other): | |||
return other._id == self._id | |||
if other._id == self._id: | |||
if type(self) == type(other): |
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.
I'd say that it makes sense to broke things up on the other order, first by type and then by id. What if you pass an integer instead of a subclass? Currently it will raise an error, while if you change the order it will just return false.
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.
Yeah, like this:
if other._id != self._id:
return False
if type(self) != type(other):
return False
return True
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.
It will still fail, it should be this way:
if type(self) != type(other):
return False
if other._id != self._id:
return False
return True
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.
Ah, yes.
On (Jun-02-14|11:35), josenavas wrote:
@@ -80,7 +80,10 @@ def init(self, id_):
self.id = iddef __eq__(self, other):
return other._id == self._id
if other._id == self._id:
if type(self) == type(other):
It will still fail, it should be this way:
if type(self) != type(other): return False if other._id != self._id: return False return True
Reply to this email directly or view it on GitHub:
https://github.com/biocore/qiita/pull/67/files#r13299908
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.
Eh, ok. Fixed.
I know you haven't change it, but can you remove the |
Nevermind. Done. |
@@ -80,7 +79,11 @@ def __init__(self, id_): | |||
self._id = id_ | |||
|
|||
def __eq__(self, other): | |||
return other._id == self._id | |||
if other._id != self._id: |
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.
The order here is still wrong, check my previous comment.
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.
ID is faster to check though, so probably faster this way. If the ID is different, it doesn't matter if it's the same type or not; it's considered not equal.
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.
Faster, but it will raise an error instead of returning false if "other" is not a subclass of BaseClass
. Please check all the comments that we make in the code.
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.
ah, right. Didn't catch that was why the error was raised during the convo.
It looks good to me now. |
I think this is good now. |
@wasade @ElDeveloper if it looks good to you, feel free to merge it. |
Now check types are the same for base class as objects that were of different type but same ID were considered equal.
Also adds skeleton for data object so tests don't fail.