[1.7.x] Fixed #22918 -- Fixed SeparateDatabaseAndState crash

Backport of e03b7940e5 from master