In the get_max_subnet method:
|
@staticmethod |
|
def get_max_subnet(master_subnet, division_rule): |
|
try: |
|
max_subnet = ( |
|
# Get the highest subnet created for this master_subnet |
|
Subnet.objects.filter(master_subnet_id=master_subnet.id) |
|
.order_by('-created') |
|
.first() |
|
.subnet |
|
) |
Relying on the creation date to order the subnets will not work in all cases.
Ordering by subnet will work on PostgreSQL, which is the DB we use in almost all deployments, while on SQlite it won't work, I think an acceptable solution right now is to check which DB is being used in the default database and depending on that order either by subnet or fallback on creation date. Let's check this behavior on MySQL too to ensure the solution is robust.
In the
get_max_subnetmethod:openwisp-controller/openwisp_controller/subnet_division/rule_types/base.py
Lines 165 to 174 in 126ab58
Relying on the creation date to order the subnets will not work in all cases.
Ordering by subnet will work on PostgreSQL, which is the DB we use in almost all deployments, while on SQlite it won't work, I think an acceptable solution right now is to check which DB is being used in the default database and depending on that order either by subnet or fallback on creation date. Let's check this behavior on MySQL too to ensure the solution is robust.