Merge pull request #2487 from loic/ticket19816

Fixed #19816 -- Pre-evaluate querysets used in direct relation assignments.
Fixed mistake in tests from commit 2039908. Refs #19816.