Changes between Version 3 and Version 4 of Ticket #28385, comment 5


Ignore:
Timestamp:
07/23/2017 10:21:39 AM (2 years ago)
Author:
Dmytryi Striletskyi
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #28385, comment 5

    v3 v4  
    1 {{{
    2 def build_instance(Model, data, db):
    3     obj = Model(**data)
    4 
    5     if obj.pk is None or (hasattr(Model, 'natural_key') and
    6                           hasattr(Model._default_manager, 'get_by_natural_key')):
    7         natural_key = obj.natural_key()
    8         try:
    9             obj.pk = Model._default_manager.db_manager(db).get_by_natural_key(*natural_key).pk
    10         except Model.DoesNotExist:
    11             pass
    12     return obj
    13 }}}
    14 
    15 I can provide this solution:
    16 >     if obj.pk is None or (hasattr(Model, 'natural_key') and hasattr(Model._default_manager, 'get_by_natural_key')):
    17 
    18 If `pk` isn't set, but `natural key` implementation exists - it goes to `updating pk` logic.
    19 
    20 I did test manually, it seems bug is fixed.
    21 Am I on right way, Daniel Knell?
     1UPD: False solution.
Back to Top