I am reading a template project from PostGIS (without actually opening in in QGIS), then changing the project CRS (amongst other changes ) then saving it to a new destination. After that, I load the newly create project. For my surprise, the Project keeps opening with a wrong CRS.
project = QgsProject()
readflags = project.ReadFlags()
readflags |= QgsProject.ReadFlag.DontResolveLayers
project.read(project_uri, readflags)
# Replace Project CRS
if project_crs.isValid():
project.setCrs(project_crs)
project.write(destination_uri)
# Read and load the new project back
self.iface.newProject()
project = QgsProject().instance()
project.read(destination_uri)
Now, the weird part. If I read the project twice, or open the project manually, the project loads with the correct CRS.