Cut any large shallots in half. Melt the butter in a 20 cm (8 inch) frying pan. Add the shallots and fry over a medium heat for 5 minutes until just beginning to colour.
Add the sugar and fry for 5 more minutes or until caramelized, turning from time to time so that the shallots cook evenly. Add the vinegar, leaves from the thyme sprigs and some seasoning and cook for 2 minutes.
If your frying pan has a metal handle then leave the shallots to cool for 20 minutes in the pan, if not transfer to a heavy based 20 cm (8 inch) buttered round cake tin.
Roll out the pastry on a lightly floured surface and trim to a 20 cm (8 inch) circle. Arrange on top of the onions and tuck down the sides of the frying pan or cake tin. Cover and chill until required.
When ready to serve, remove the cover and bake in a preheated oven, 200°C (400°F), Gas Mark 6, for 25–30 minutes until the pastry is well risen and golden. Leave to stand for 5 minutes, then loosen the edges with a knife. Cover with a serving plate or chopping board and invert the pan or cake tin on to the plate then remove. Serve warm, cut into wedges with a green leaf salad.