Browse Source

Fixed #36177 -- Added a trailing newline to JSON serializer. (#19232)

Tom Carrick 1 week ago
parent
commit
8df5ce80d2

+ 0 - 5
.editorconfig

@@ -18,11 +18,6 @@ max_line_length = 88
 [*.html]
 indent_size = 2
 
-# The JSON files contain newlines inconsistently
-[*.json]
-indent_size = 2
-insert_final_newline = ignore
-
 [**/admin/js/vendor/**]
 indent_style = ignore
 indent_size = ignore

+ 1 - 2
django/core/serializers/json.py

@@ -39,8 +39,7 @@ class Serializer(PythonSerializer):
         if self.options.get("indent"):
             self.stream.write("\n")
         self.stream.write("]")
-        if self.options.get("indent"):
-            self.stream.write("\n")
+        self.stream.write("\n")
 
     def end_object(self, obj):
         # self._current has the field data

+ 2 - 1
docs/releases/6.0.txt

@@ -293,7 +293,8 @@ of each library are the first to add or confirm compatibility with Python 3.12:
 Miscellaneous
 -------------
 
-* ...
+* The :ref:`JSON <serialization-formats-json>` serializer now writes a newline
+  at the end of the output, even without the ``indent`` option set.
 
 .. _deprecated-features-6.0:
 

+ 1 - 1
tests/fixtures/fixtures/db_fixture_1.default.json

@@ -7,4 +7,4 @@
             "pub_date": "2006-06-16 14:00:00"
         }
     }
-]
+]

+ 1 - 1
tests/fixtures/fixtures/db_fixture_3.nosuchdb.json

@@ -7,4 +7,4 @@
             "pub_date": "2006-06-16 14:00:00"
         }
     }
-]
+]

+ 1 - 1
tests/fixtures/fixtures/fixture1.json

@@ -31,4 +31,4 @@
             "title": "News Stories"
         }
     }
-]
+]

+ 1 - 1
tests/fixtures/fixtures/fixture2.json

@@ -15,4 +15,4 @@
             "pub_date": "2006-06-16 15:00:00"
         }
     }
-]
+]

+ 1 - 1
tests/fixtures_regress/fixtures/absolute.json

@@ -6,4 +6,4 @@
             "name": "Load Absolute Path Test"
         }
     }
-]
+]

+ 1 - 1
tests/fixtures_regress/fixtures/big-fixture.json

@@ -80,4 +80,4 @@
             "channels": [6]
         }
     }
-]
+]

+ 1 - 1
tests/fixtures_regress/fixtures/empty.json

@@ -1 +1 @@
-[]
+[]

+ 1 - 1
tests/fixtures_regress/fixtures/forward_ref.json

@@ -14,4 +14,4 @@
             "name": "Neal Stephenson"
         }
     }
-]
+]

+ 1 - 1
tests/fixtures_regress/fixtures/forward_ref_bad_data.json

@@ -14,4 +14,4 @@
             "name": "Neal Stephenson"
         }
     }
-]
+]

+ 1 - 1
tests/fixtures_regress/fixtures/non_natural_1.json

@@ -22,4 +22,4 @@
             "stores": [11]
         }
     }
-]
+]

+ 1 - 1
tests/fixtures_regress/fixtures/sequence.json

@@ -9,4 +9,4 @@
             "weight": 1.2
         }
     }
-]
+]

+ 1 - 1
tests/gis_tests/geogapp/fixtures/initial.json

@@ -95,4 +95,4 @@
        "poly" : "POLYGON ((-95.447918 29.727275, -95.447418 29.71003, -95.446918 29.69013, -95.454318 29.68893, -95.475819 29.68903, -95.475819 29.69113, -95.484419 29.69103, -95.484519 29.69903, -95.480419 29.70133, -95.480419 29.69833, -95.474119 29.69833, -95.474119 29.70453, -95.472719 29.71283, -95.468019 29.71293, -95.468219 29.720229, -95.464018 29.720229, -95.464118 29.724529, -95.463018 29.725929, -95.459818 29.726129, -95.459918 29.720329, -95.451418 29.720429, -95.451775 29.726303, -95.451318 29.727029, -95.447918 29.727275))"
     }
   }
-]
+]

+ 1 - 1
tests/m2m_through_regress/fixtures/m2m_through.json

@@ -31,4 +31,4 @@
             "price": "100"
         }
     }
-]
+]

+ 1 - 1
tests/multiple_database/fixtures/multidb-common.json

@@ -7,4 +7,4 @@
             "published": "2009-7-8"
         }
     }
-]
+]

+ 1 - 1
tests/multiple_database/fixtures/multidb.other.json

@@ -23,4 +23,4 @@
             "editor": ["Chris Mills"]
         }
     }
-]
+]

+ 1 - 1
tests/multiple_database/fixtures/pets.json

@@ -15,4 +15,4 @@
             "owner": 2
         }
     }
-]
+]

+ 1 - 1
tests/proxy_models/fixtures/mypeople.json

@@ -6,4 +6,4 @@
             "name": "Elvis Presley"
         }
     }
-]
+]

+ 2 - 1
tests/serializers/tests.py

@@ -489,7 +489,8 @@ class SerializerAPITests(SimpleTestCase):
         self.assertIs(serializer.stream_class, File)
         self.assertIsInstance(serializer.stream, File)
         self.assertEqual(
-            data, '[{"model": "serializers.score", "pk": 1, "fields": {"score": 3.4}}]'
+            data,
+            '[{"model": "serializers.score", "pk": 1, "fields": {"score": 3.4}}]\n',
         )
 
 

+ 1 - 1
tests/servers/fixtures/testdata.json

@@ -13,4 +13,4 @@
       "name": "robert"
     }
   }
-]
+]