Skip to content

Commit

Permalink
Improve clarity of comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gherceg committed Jan 26, 2024
1 parent 9f47699 commit 52a7011
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions corehq/apps/dump_reload/sql/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,14 @@ def dump(self, output_stream):
the following reasons:
use_natural_primary_keys is necessary for sharded models to ensure the primary key, which will not be
unique across shards, is not used.
use_natural_foreign_keys is necessary for fk relationships where the primary key is used. For instance,
SQLUserData foreign keys to auth.User, relying on the auth.User primary key. However auth.User has a
natural_key method defined, so it's primary key will not be included due to use_natural_primary_keys
being set to True. To resolve, we can use_natural_foreign_keys for any object that has get_by_natural_key
defined, which auth.User does. This enables identifying the correct auth.User when loading serialized
SQLUserData back into a database.
unique across shards, is not used. This can be thought of as "use natural primary keys when defined".
use_natural_foreign_keys is necessary for foreign keys that reference primary keys on models that have a
natural_key method defined. This can be thought of as "use natural foreign keys when defined". For example,
SQLUserData has a foreign key to User based on the primary key. However a natural_key method is defined on
the User model, so its primary key will not be serialized when use_natural_primary_keys=True. To resolve,
we set use_natural_foreign_keys=True which will result in natural keys being serialized as part of the
foreign key field when referencing a model with natural_key defined.
"""
stats = Counter()
objects = get_objects_to_dump(
Expand Down
4 changes: 2 additions & 2 deletions corehq/form_processor/models/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@ def __init__(self, *args, **kwargs):

def natural_key(self):
"""
Django recommends always returning a tuple in natural_key methods:
Django requires returning a tuple in natural_key methods:
https://docs.djangoproject.com/en/3.2/topics/serialization/#serialization-of-natural-keys
We intentionally do not follow this to optimize corehq.apps.dump_reload.sql.load.SqlDataLoader when other
models foreign key to CommCareCase or XFormInstance. This means our loader code is subject to break in
models reference CommCareCase or XFormInstance via a foreign key. This means our loader code may break in
future Django upgrades.
"""
# necessary for dumping models from a sharded DB so that we exclude the
Expand Down
4 changes: 2 additions & 2 deletions corehq/form_processor/models/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,10 @@ def original_operations(self):

def natural_key(self):
"""
Django recommends always returning a tuple in natural_key methods:
Django requires returning a tuple in natural_key methods:
https://docs.djangoproject.com/en/3.2/topics/serialization/#serialization-of-natural-keys
We intentionally do not follow this to optimize corehq.apps.dump_reload.sql.load.SqlDataLoader when other
models foreign key to CommCareCase or XFormInstance. This means our loader code is subject to break in
models reference CommCareCase or XFormInstance via a foreign key. This means our loader code may break in
future Django upgrades.
"""
# necessary for dumping models from a sharded DB so that we exclude the
Expand Down

0 comments on commit 52a7011

Please sign in to comment.