Fix handling of generating relative path to parent (#18460)