@@ -266,35 +266,28 @@ def _serialize_machine(self, machine: Any) -> dict[str, Any]:
266266 return d
267267
268268 def format_machine_details_response (self , machine_data : dict ) -> dict :
269- """Format machine details with default fields, including provider_data fields."""
269+ """Format machine details for the API detail endpoint.
270+
271+ Returns every field on the source dict so adding a domain field to
272+ ``Machine`` automatically surfaces in the detail payload — no
273+ formatter update needed. ``id`` is kept as a legacy alias for
274+ ``machine_id``; ``provider`` is hard-stamped because the default
275+ strategy is the bound provider.
276+ """
270277 provider_data : dict [str , Any ] = machine_data .get ("provider_data" ) or {}
278+ machine_id = machine_data .get ("machine_id" ) or machine_data .get ("id" )
271279
272- result : dict [str , Any ] = {
273- "id" : machine_data .get ("id" ),
274- "name" : machine_data .get ("name" ),
275- "status" : machine_data .get ("status" ),
276- "provider" : "default" ,
277- "instance_type" : machine_data .get ("instance_type" ),
278- "image_id" : machine_data .get ("image_id" ),
279- "private_ip" : machine_data .get ("private_ip" ),
280- "public_ip" : machine_data .get ("public_ip" ),
281- "subnet_id" : machine_data .get ("subnet_id" ),
282- "security_group_ids" : machine_data .get ("security_group_ids" ),
283- "status_reason" : machine_data .get ("status_reason" ),
284- "launch_time" : machine_data .get ("launch_time" ),
285- "termination_time" : machine_data .get ("termination_time" ),
286- "tags" : machine_data .get ("tags" ),
287- }
280+ result : dict [str , Any ] = {** machine_data }
281+ result ["id" ] = machine_id
282+ result ["machine_id" ] = machine_id
283+ result ["provider" ] = "default"
284+ result ["provider_data" ] = provider_data or None
288285
289- # Provider_data fields — prefer top-level if already present, else pull from provider_data
286+ # Promote selected provider_data sub-fields to the top level when the
287+ # source dict did not already carry them — matches list endpoint shape.
290288 for key in ("region" , "availability_zone" , "vcpus" , "health_checks" ):
291- val = (
292- machine_data .get (key )
293- if machine_data .get (key ) is not None
294- else provider_data .get (key )
295- )
296- if val is not None :
297- result [key ] = val
289+ if result .get (key ) is None and provider_data .get (key ) is not None :
290+ result [key ] = provider_data [key ]
298291
299292 cloud_host_id = machine_data .get ("cloud_host_id" ) or provider_data .get ("cloud_host_id" )
300293 if cloud_host_id is not None :
0 commit comments