Re: [Django] #29871: Resetting primary key for a derived object does not work

2018-10-23 Thread Django
#29871: Resetting primary key for a derived object does not work
-+-
 Reporter:  Victor Porton|Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Victor Porton):

 Replying to [comment:10 Victor Porton]:
 > My test with this patch passed.

 When to expect it to be included in Django distribution?

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.7442d14dab1d849b334ba7e6e06d8c5b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29871: Resetting primary key for a derived object does not work

2018-10-22 Thread Django
#29871: Resetting primary key for a derived object does not work
-+-
 Reporter:  Victor Porton|Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Victor Porton):

 Replying to [comment:9 Simon Charette]:
 > The following should do

 My test with this patch passed.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.781b10b077ca117e6dcb441186465908%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29871: Resetting primary key for a derived object does not work

2018-10-22 Thread Django
#29871: Resetting primary key for a derived object does not work
-+-
 Reporter:  Victor Porton|Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Simon Charette):

 The following should do

 {{{
 diff --git a/django/db/models/base.py b/django/db/models/base.py
 index 751f42bb9b..d3141d6180 100644
 --- a/django/db/models/base.py
 +++ b/django/db/models/base.py
 @@ -553,6 +553,8 @@ class Model(metaclass=ModelBase):
  return getattr(self, meta.pk.attname)

  def _set_pk_val(self, value):
 +for parent_link in self._meta.parents.values():
 +setattr(self, parent_link.target_field.attname, value)
  return setattr(self, self._meta.pk.attname, value)

  pk = property(_get_pk_val, _set_pk_val)
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.e96d64cf7fcc45a692128b581cc3a058%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29871: Resetting primary key for a derived object does not work

2018-10-22 Thread Django
#29871: Resetting primary key for a derived object does not work
-+-
 Reporter:  Victor Porton|Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Victor Porton):

 Replying to [comment:7 Simon Charette]:
 > Could you confirm that the following patch work for you when setting
 `self.pk = None` in `reset()`.

 No, the patch does not make `self.pk = None` to work!

 {{{
 pip install django
 ...
 patch -p1 < ~/t/patch.diff
 cd /home/porton/Projects/test/testsave
 (env) testsave,0$ ./manage.py test
 Creating test database for alias 'default'...
 System check identified no issues (0 silenced).
 F
 ==
 FAIL: test_f_true (test1.tests.SaveTestCase)
 --
 Traceback (most recent call last):
   File "/home/porton/Projects/test/testsave/test1/tests.py", line 19, in
 test_f_true
 self.assertTrue(obj.f)
 AssertionError: False is not true

 --
 Ran 1 test in 0.005s

 FAILED (failures=1)
 Destroying test database for alias 'default'...
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.26b63dc05790acf5ddf7c91ebd11f7d2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29871: Resetting primary key for a derived object does not work

2018-10-22 Thread Django
#29871: Resetting primary key for a derived object does not work
-+-
 Reporter:  Victor Porton|Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Simon Charette):

 Thanks for the extra details Victor.

 Could you confirm that the following patch work for you when setting
 `self.pk = None` in `reset()`.

 {{{
 diff --git a/django/db/models/base.py b/django/db/models/base.py
 index 751f42bb9b..535928ce05 100644
 --- a/django/db/models/base.py
 +++ b/django/db/models/base.py
 @@ -553,7 +553,11 @@ class Model(metaclass=ModelBase):
  return getattr(self, meta.pk.attname)

  def _set_pk_val(self, value):
 -return setattr(self, self._meta.pk.attname, value)
 +field = self._meta.pk
 +setattr(self, field.attname, value)
 +while getattr(field, 'parent_link', False):
 +field = field.target_field
 +setattr(self, field.attname, value)

  pk = property(_get_pk_val, _set_pk_val)
 }}}

 This code should make sure that setting `self.pk = None` does
 `self.item_ptr_id = self.id = None` for any level of concrete model
 inheritance. That should be enough for `save()` to create new objects from
 my local testing.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.9bce2467efddfb8954aa0759935d029e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29871: Resetting primary key for a derived object does not work

2018-10-22 Thread Django
#29871: Resetting primary key for a derived object does not work
-+-
 Reporter:  Victor Porton|Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Victor Porton):

 Replying to [comment:5 Simon Charette]:
 > Hello Victor, could you provide more details about what exactly you are
 trying to achieve here?
 >
 > So far you've only provided a test case that fails. Are you trying to
 create a copy of an existing objects using MTI?

 Yes. I am trying to create a copy of an existing object using MTI.

 > Providing more details about what you are trying to achieve and why
 you're expecting the test to pass would help us to determining if this is
 actually a bug.

 I am trying to create a copy of a `Derived` object which was in the DB
 long before. The copy should contain all fields of the `Derived` model and
 all fields of its base models.

 As for now, I do not know a reliable and not error-prone (such as
 depending on usage of base of derived class) way to do this. If there is
 no such way, it is a missing feature in Django and this should be
 considered at least as a feature suggestion.

 In my real code I may have several levels of inheritance (not just `Item`
 and `Derived`).

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.68ea1d336bf114201014a47568a314b7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29871: Resetting primary key for a derived object does not work

2018-10-22 Thread Django
#29871: Resetting primary key for a derived object does not work
-+-
 Reporter:  Victor Porton|Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Simon Charette):

 Hello Victor, could you provide more details about what exactly you are
 trying to achieve here?

 So far you've only provided a test case that fails. Are you trying to
 create a copy of an existing objects using MTI?

 Providing more details about what you are trying to achieve and why you're
 expecting the test to pass would help us to determining if this is
 actually a bug.

 Thanks!

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.4a39c35470e84fb7f99b39696466db41%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29871: Resetting primary key for a derived object does not work

2018-10-22 Thread Django
#29871: Resetting primary key for a derived object does not work
-+-
 Reporter:  Victor Porton|Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Victor Porton):

 Can we consider that `self.pk = None` does not work too, as a bug?

 At least it is a counterintuitive (and dangerous for the data!) behavior.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.b38863044837308edfefed2e200bf84d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29871: Resetting primary key for a derived object does not work

2018-10-21 Thread Django
#29871: Resetting primary key for a derived object does not work
-+-
 Reporter:  Victor Porton|Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Victor Porton):

 @Simon Charette

 No `self.pk = None` does not work too.

 It seems that there is no reliable (not error-prone, as depending on the
 usage of base or derived class) way to do this :-(

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.fd44516534be7e8c84923361d5269e21%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29871: Resetting primary key for a derived object does not work

2018-10-20 Thread Django
#29871: Resetting primary key for a derived object does not work
-+-
 Reporter:  Victor Porton|Owner:  nobody
 Type:  Bug  |   Status:  closed
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  invalid
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Simon Charette):

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


Comment:

 I agree with Tim here.

 It feels like what you're after is `self.pk = None` as it will be alias
 for `self.item_ptr` for `Derived` instances and `self.uid` for `Item`
 instances.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.d4b473b81be9c5cbb0ae5665f1d10c17%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29871: Resetting primary key for a derived object does not work

2018-10-20 Thread Django
#29871: Resetting primary key for a derived object does not work
-+-
 Reporter:  Victor Porton|Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Tim Graham):

 I'm not sure if this is a bug. The test passes after adding `self.item_ptr
 = None` to `Item.reset()`. Is that the behavior you're looking for?

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.4b1bf2e5c1dcb76145769fd9d405d5cb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #29871: Resetting primary key for a derived object does not work

2018-10-20 Thread Django
#29871: Resetting primary key for a derived object does not work
-+-
 Reporter:  Victor Porton|Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  2.1
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Victor Porton):

 * Attachment "bug.tar.gz" added.


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.e52250819989cac85a1f734b1bde39a0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.