﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35977	Serializing ManyToMany fields produces inconsistent order (on Postgres)	Alexander Todorov		"**Context:** 

I am migrating data from one DB to another and using serialization to dump the contents into JSON and then compare them with diff. On occasion it happens that models which have a ManyToMany field result in a data dump where the collection of PKs isn't sorted in exactly the same order when comparing the 2 data dumps.  This appears to happen quite often on Postgres and I believe it is coming from Postgres itself - i.e. when an explicit order isn't specified it sometimes returns the results in the best way it sees fit.

**Proposal:** 

Add a call to `.order_by(""pk"")` when handling m2m field serialization to make the results predictable. 

**Additional information**

I have a commit in my own fork, https://github.com/atodorov/django/commit/1ae2f28ba42f28399f58d3edda98a35088225deb, which works great for me. 

LMK if you want me to open a pull request."	New feature	closed	Core (Serialization)	5.1	Normal	wontfix			Unreviewed	0	0	0	0	0	0
