Heat oven to 200C/180C fan/gas 6.
Peel the onions and cut each into 6 wedges
through the root. Heat the oil in a large pan,
add onions, then gently fry for 20 mins
until softened and lightly coloured.
Add the mushrooms, sugar, salt and
pepper and give it a good stir. Gently
cook, stirring now and then for a further
5 mins. Stir in the walnuts. Line the base
of a 20-23cm sandwich cake tin (not
loose-based) with baking parchment.
Spoon over the onion mixture and press
it down lightly. Crumble the cheese over.
Roll out the pastry and trim to a round,
about 5cm larger than the tin. Put
the pastry over the filling and tuck in the
ends. Bake for 35-40 mins until the pastry
is crisp and golden. Cool for 5 mins in the
tin, then turn out onto a flat plate and cut
into wedges. Serve with a green salad.