You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by Apache Bloodhound <bl...@incubator.apache.org> on 2013/01/04 17:22:08 UTC

[Apache Bloodhound] #336: bhdashboard.model.ModelBase insert method fails if no unique fields specified

#336: bhdashboard.model.ModelBase insert method fails if no unique fields
specified
--------------------------+--------------------
 Reporter:  franco        |      Owner:  nobody
     Type:  defect        |     Status:  new
 Priority:  critical      |  Milestone:
Component:  multiproduct  |    Version:  0.3.0
 Keywords:                |
--------------------------+--------------------
 When a persistent class that extends ModelBase has an empty list of unique
 fields specified in the metadata, as it is the case of ProductResourceMap
 and there is at least one record in the table, every insert attempt fails
 indicating TracError: [object_name]  already exists.

 The problem is that inside the insert method, there is an attempt to find
 if there is some record in the database that matches the unique fields
 values of the record to be inserted.


 This select always returns some values if the unique fields meta is an
 empty list.


 There should be an evaluation previous to the query, to ensure that the
 query is made only if there is some value indicated in the unique fields
 meta data.

 PD. I find no component good enough to relate this ticket to...
 multiproduct seems to be the closest one since it was the first component
 using ModelBase

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/336>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound (incubating) issue tracker

Re: [Apache Bloodhound] #336: bhdashboard.model.ModelBase insert method fails if no unique fields specified

Posted by Apache Bloodhound <bl...@incubator.apache.org>.
#336: bhdashboard.model.ModelBase insert method fails if no unique fields
specified
---------------------------+------------------------------
  Reporter:  franco        |      Owner:  nobody
      Type:  defect        |     Status:  closed
  Priority:  critical      |  Milestone:  Release 5
 Component:  multiproduct  |    Version:  0.3.0
Resolution:  fixed         |   Keywords:  model sql insert
---------------------------+------------------------------
Changes (by gjm):

 * status:  new => closed
 * resolution:   => fixed


Comment:

 r1447578 adds a generalised test case based on franco's that does not rely
 on a specific existing model

 r1447579 applies the suggested fix

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/336#comment:6>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound (incubating) issue tracker

Re: [Apache Bloodhound] #336: bhdashboard.model.ModelBase insert method fails if no unique fields specified

Posted by Apache Bloodhound <bl...@incubator.apache.org>.
#336: bhdashboard.model.ModelBase insert method fails if no unique fields
specified
---------------------------+------------------------------
  Reporter:  franco        |      Owner:  nobody
      Type:  defect        |     Status:  new
  Priority:  critical      |  Milestone:  Release 5
 Component:  multiproduct  |    Version:  0.3.0
Resolution:                |   Keywords:  model sql insert
---------------------------+------------------------------

Comment (by gjm):

 Replying to [comment:3 olemis]:
 > IMO that's not enough due to the fact that `WHERE` clause will check for
 the combination of unique fields . IOW for UNIQUE checks the logic op
 should be `OR` instead of `AND` .
 >
 > CMIIW

 Well, the point of the change is that we get failure if there are no
 unique fields defined. As such, we only need to run the code here if
 {{{self._meta['unique_fields']}}} is not empty.

 Beyond that, we might want to distinguish between unique individually and
 fields that are unique together but that can be in a new ticket.

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/336#comment:5>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound (incubating) issue tracker

Re: [Apache Bloodhound] #336: bhdashboard.model.ModelBase insert method fails if no unique fields specified

Posted by Apache Bloodhound <bl...@incubator.apache.org>.
#336: bhdashboard.model.ModelBase insert method fails if no unique fields
specified
---------------------------+------------------------------
  Reporter:  franco        |      Owner:  nobody
      Type:  defect        |     Status:  new
  Priority:  critical      |  Milestone:
 Component:  multiproduct  |    Version:  0.3.0
Resolution:                |   Keywords:  model sql insert
---------------------------+------------------------------
Changes (by olemis):

 * keywords:   => model sql insert


Comment:

 Replying to [comment:2 gjm]:
 >
 [...]
 > The diff below would be similar to your suggestion.
 >
 > {{{
 > #!diff
 > Index: bloodhound_dashboard/bhdashboard/model.py
 > ===================================================================
 > --- bloodhound_dashboard/bhdashboard/model.py (revision 1429887)
 > +++ bloodhound_dashboard/bhdashboard/model.py (working copy)
 > @@ -145,7 +145,7 @@
 >                                        for k in
 self._meta['key_fields']]))):
 >              sdata = {'keys':','.join(["%s='%s'" % (k, self._data[k])
 >                                       for k in
 self._meta['key_fields']])}
 > -        elif len(self.select(self._env, where =
 > +        elif self._meta['unique_fields'] and len(self.select(self._env,
 where =
 >                                  dict([(k,self._data[k])
 > }}}
 >
 > This appears to fix the testcase you suggest but I have not checked
 through the full consequences of the change yet.

 IMO that's not enough due to the fact that `WHERE` clause will check for
 the combination of unique fields . IOW for UNIQUE checks the logic op
 should be `OR` instead of `AND` .

 CMIIW

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/336#comment:3>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound (incubating) issue tracker

Re: [Apache Bloodhound] #336: bhdashboard.model.ModelBase insert method fails if no unique fields specified

Posted by Apache Bloodhound <bl...@incubator.apache.org>.
#336: bhdashboard.model.ModelBase insert method fails if no unique fields
specified
---------------------------+--------------------
  Reporter:  franco        |      Owner:  nobody
      Type:  defect        |     Status:  new
  Priority:  critical      |  Milestone:
 Component:  multiproduct  |    Version:  0.3.0
Resolution:                |   Keywords:
---------------------------+--------------------

Comment (by gjm):

 Thanks franco. Good find. The diff below would be similar to your
 suggestion.

 {{{
 #!diff
 Index: bloodhound_dashboard/bhdashboard/model.py
 ===================================================================
 --- bloodhound_dashboard/bhdashboard/model.py   (revision 1429887)
 +++ bloodhound_dashboard/bhdashboard/model.py   (working copy)
 @@ -145,7 +145,7 @@
                                        for k in
 self._meta['key_fields']]))):
              sdata = {'keys':','.join(["%s='%s'" % (k, self._data[k])
                                       for k in self._meta['key_fields']])}
 -        elif len(self.select(self._env, where =
 +        elif self._meta['unique_fields'] and len(self.select(self._env,
 where =
                                  dict([(k,self._data[k])
 }}}

 This appears to fix the testcase you suggest but I have not checked
 through the full consequences of the change yet.

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/336#comment:2>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound (incubating) issue tracker

Re: [Apache Bloodhound] #336: bhdashboard.model.ModelBase insert method fails if no unique fields specified

Posted by Apache Bloodhound <bl...@incubator.apache.org>.
#336: bhdashboard.model.ModelBase insert method fails if no unique fields
specified
---------------------------+------------------------------
  Reporter:  franco        |      Owner:  nobody
      Type:  defect        |     Status:  closed
  Priority:  critical      |  Milestone:  Release 5
 Component:  multiproduct  |    Version:  0.3.0
Resolution:  fixed         |   Keywords:  model sql insert
---------------------------+------------------------------

Comment (by gjm):

 #400 opened to allow for more than one set of unique together fields

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/336#comment:7>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound (incubating) issue tracker

Re: [Apache Bloodhound] #336: bhdashboard.model.ModelBase insert method fails if no unique fields specified

Posted by Apache Bloodhound <bl...@incubator.apache.org>.
#336: bhdashboard.model.ModelBase insert method fails if no unique fields
specified
---------------------------+------------------------------
  Reporter:  franco        |      Owner:  nobody
      Type:  defect        |     Status:  new
  Priority:  critical      |  Milestone:  Release 5
 Component:  multiproduct  |    Version:  0.3.0
Resolution:                |   Keywords:  model sql insert
---------------------------+------------------------------
Changes (by gjm):

 * milestone:   => Release 5


-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/336#comment:4>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound (incubating) issue tracker

Re: [Apache Bloodhound] #336: bhdashboard.model.ModelBase insert method fails if no unique fields specified

Posted by Apache Bloodhound <bl...@incubator.apache.org>.
#336: bhdashboard.model.ModelBase insert method fails if no unique fields
specified
---------------------------+------------------------------
  Reporter:  franco        |      Owner:  gjm
      Type:  defect        |     Status:  closed
  Priority:  critical      |  Milestone:  Release 5
 Component:  multiproduct  |    Version:  0.3.0
Resolution:  fixed         |   Keywords:  model sql insert
---------------------------+------------------------------
Changes (by rjollos):

 * owner:  nobody => gjm


-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/336#comment:8>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound (incubating) issue tracker

Re: [Apache Bloodhound] #336: bhdashboard.model.ModelBase insert method fails if no unique fields specified

Posted by Apache Bloodhound <bl...@incubator.apache.org>.
#336: bhdashboard.model.ModelBase insert method fails if no unique fields
specified
---------------------------+--------------------
  Reporter:  franco        |      Owner:  nobody
      Type:  defect        |     Status:  new
  Priority:  critical      |  Milestone:
 Component:  multiproduct  |    Version:  0.3.0
Resolution:                |   Keywords:
---------------------------+--------------------

Comment (by franco):

 This
 [https://issues.apache.org/bloodhound/attachment/ticket/336/bloodhound_t336
 attachment] is a patch that adds a test case to multiproduct.test.model
 module, reproducing the error

 Sorry not submitting a solution patch.. I have some code related to
 ModelBase that is not quite finished yet... in my local copy I added a
 first condition like this:[[BR]]

 {{{
     elif len(self._meta['unique_fields']) \
                        and len(self.select(self._env, where = ...
 }}}


 Best regards,

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/336#comment:1>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound (incubating) issue tracker