Step 1Halve the squash and scrape away the seeds and membranes, then cut the flesh into 4-inch-square pieces. (If using butternut, cut it in half crosswise, just above the bulbous bottom part, then cut these halves into lengthwise quarters and scrape away the seeds and membranes.)
Step 2Steam the squash until tender, 15 to 20 minutes, then transfer to a colander and allow to cool and drain for another 15 minutes (butternut squash will not be watery). When the squash has cooled, peel and place in a bowl. Mash with a fork, a large wooden spoon, a potato masher or a pestle.
Step 3Heat the oil over medium heat in a large nonstick skillet and add the onion. Cook, stirring, until tender, about 5 minutes, then stir in the garlic. Cook until fragrant, another minute or two. Remove from the heat and toss with the squash, sage, rice, parsley, Gruyere and Parmesan cheeses, all but 2 tablespoons of the eggs, salt and pepper to taste. Taste and adjust seasonings.
Step 4Heat the oven to 375 degrees. Oil a 10-inch or 12-inch tart pan with a removable bottom or springform pan.
Step 5Roll out two thirds of the pastry and line the pan with the edges overhanging. Fill the crust with the squash mixture. Top with the remaining pastry, then crimp the edges of the top and bottom pastry together. Cut 4 small slits in the top crust with a sharp knife, brush with the reserved beaten egg and place in the oven. Bake until golden brown, 45 to 50 minutes. Allow to rest for at least 10 minutes before serving. This can also be served at room temperature.