You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But when I called ShardingApp.objects.create() I got shard = None in the database.
The bug is that pre_save signal is called only if shard field has attribute django_sharding__stores_shard = True which is not correct for models.CharField used in ShardedByMixin.
I've tried to solve the problem by replacing default CharField with ShardStorageCharField:
@model_config(database='default')classShardingApp(BaseModel, ShardedByMixin):
# Need to redefine it, as choices don't see it during class creationSHARD_CHOICES= ((i, i) foriin_get_primary_shards())
name=models.CharField(max_length=50, default='Test')
# Here I redeclared shard field.shard=ShardStorageCharField(max_length=120, blank=True, null=True, choices=SHARD_CHOICES,
shard_group='shards_by_app_group')
defget_shard_key(self):
returnself.pk
But this also doesn't work: pre_signal is executed, but it gets ShardingApp model as a sender. And in this line it wants django_sharding__shard_group attribute:
@model_config(database='default')classShardingApp(BaseModel, ShardedByMixin):
# BUG Signal wants it. I suggest adding that in the docsdjango_sharding__shard_group='shards_by_app_group'SHARD_CHOICES= ((i, i) foriin_get_primary_shards())
name=models.CharField(max_length=50, default='Test')
# BUG Signal is not called if it's simple CharField. I suggest replace field in ShardedByMixin.shard=ShardStorageCharField(max_length=120, blank=True, null=True, choices=SHARD_CHOICES,
shard_group=django_sharding__shard_group)
defget_shard_key(self):
returnself.pk
My suggestions are:
Replace CharFIeld with ShardStorageCharField in ShardedByMixin by default
Write in the docs, that django_sharding__shard_group = 'shards_by_app_group' should be defined in ShardedBy model.
The text was updated successfully, but these errors were encountered:
Hey.
In my test app I want to shard by
ShardingApp
model. And splitShardedUser
into multiple database shards. Here is the code, I expected to work:But when I called
ShardingApp.objects.create()
I gotshard = None
in the database.The bug is that pre_save signal is called only if
shard
field has attributedjango_sharding__stores_shard = True
which is not correct for models.CharField used inShardedByMixin
.I've tried to solve the problem by replacing default
CharField
withShardStorageCharField
:But this also doesn't work: pre_signal is executed, but it gets
ShardingApp
model as a sender. And in this line it wantsdjango_sharding__shard_group
attribute:So the resulting working code was:
My suggestions are:
The text was updated successfully, but these errors were encountered: