I think that the raster layer may not display properly if the project's crs is not set.
QgsProject.instance().crs()
# <QgsCoordinateReferenceSystem: invalid>
Setting crs might help.
QgsProject.instance().setCrs(QgsCoordinateReferenceSystem("EPSG:3857"))
(Set the EPSG value to suit your project)