← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~ack/maas:rdns-hostnames-array-migration-fix into maas:master

 

Alberto Donato has proposed merging ~ack/maas:rdns-hostnames-array-migration-fix into maas:master.

Commit message:
fix migration for RDNS hostnames column, to handle cases wher content is alrady
an array.

This can happen if the controller updates its own row before the migration is
completed.
In that case it will write a postgres array, while the migration expected JSON.



Requested reviews:
  MAAS Maintainers (maas-maintainers)

For more details, see:
https://code.launchpad.net/~ack/maas/+git/maas/+merge/436130
-- 
Your team MAAS Maintainers is requested to review the proposed merge of ~ack/maas:rdns-hostnames-array-migration-fix into maas:master.
diff --git a/src/maasserver/migrations/maasserver/0291_rdns_hostnames_as_array.py b/src/maasserver/migrations/maasserver/0291_rdns_hostnames_as_array.py
index 2c9bf23..03b3f4c 100644
--- a/src/maasserver/migrations/maasserver/0291_rdns_hostnames_as_array.py
+++ b/src/maasserver/migrations/maasserver/0291_rdns_hostnames_as_array.py
@@ -13,8 +13,12 @@ QUERIES = (
       result text[] = '{}'::text[];
     BEGIN
       IF content != '' THEN
-        SELECT array_agg(sub.r) INTO result
-        FROM (SELECT json_array_elements_text(content::json) AS r) AS sub;
+        BEGIN
+          SELECT array_agg(sub.r) INTO result
+          FROM (SELECT json_array_elements_text(content::json) AS r) AS sub;
+        EXCEPTION
+          WHEN invalid_text_representation THEN RETURN content::text[];
+        END;
       END IF;
       RETURN result;
     END;

Follow ups