Repository: getmoto/moto

Issue:
Regression when using mock_batch_simple since 4.0.7
Since moto 4.0.7 we noticed some regressions in our unit tests using `mock_batch_simple`. All the jobs container details are empty while they weren't in version 4.0.6.

For instance this code is now failing because there's no 'command' key in the dictionary.

```python
    result = batch.describe_jobs(jobs=job_ids)['jobs']
    commands = [job['container']['command'] for job in result]
```

We think this [change](https://github.com/spulec/moto/pull/5539) is the source of the issue but I'm not sure that changing the behavior of `mock_batch_simple` was intended here.

Can you confirm this, we can try to fix if needed ?


Discussion:
Hi @bmaisonn, thanks for raising this - that was indeed an oversight. A PR would be very welcome! Let me know if you need any help with that.

Patch:
diff --git a/moto/batch/models.py b/moto/batch/models.py
--- a/moto/batch/models.py
+++ b/moto/batch/models.py
@@ -474,7 +474,6 @@ def __init__(
         self._log_backend = log_backend
         self.log_stream_name: Optional[str] = None
 
-        self.container_details: Dict[str, Any] = {}
         self.attempts: List[Dict[str, Any]] = []
         self.latest_attempt: Optional[Dict[str, Any]] = None
 
@@ -500,7 +499,7 @@ def describe(self) -> Dict[str, Any]:
         result = self.describe_short()
         result["jobQueue"] = self.job_queue.arn
         result["dependsOn"] = self.depends_on or []
-        result["container"] = self.container_details
+        result["container"] = self._container_details()
         if self.job_stopped:
             result["stoppedAt"] = datetime2int_milliseconds(self.job_stopped_at)
         if self.timeout:
@@ -508,6 +507,22 @@ def describe(self) -> Dict[str, Any]:
         result["attempts"] = self.attempts
         return result
 
+    def _container_details(self) -> Dict[str, Any]:
+        details = {}
+        details["command"] = self._get_container_property("command", [])
+        details["privileged"] = self._get_container_property("privileged", False)
+        details["readonlyRootFilesystem"] = self._get_container_property(
+            "readonlyRootFilesystem", False
+        )
+        details["ulimits"] = self._get_container_property("ulimits", {})
+        details["vcpus"] = self._get_container_property("vcpus", 1)
+        details["memory"] = self._get_container_property("memory", 512)
+        details["volumes"] = self._get_container_property("volumes", [])
+        details["environment"] = self._get_container_property("environment", [])
+        if self.log_stream_name:
+            details["logStreamName"] = self.log_stream_name
+        return details
+
     def _get_container_property(self, p: str, default: Any) -> Any:
         if p == "environment":
             job_env = self.container_overrides.get(p, default)
@@ -604,28 +619,6 @@ def run(self) -> None:
 
             self.job_started_at = datetime.datetime.now()
 
-            self.container_details["command"] = self._get_container_property(
-                "command", []
-            )
-            self.container_details["privileged"] = self._get_container_property(
-                "privileged", False
-            )
-            self.container_details[
-                "readonlyRootFilesystem"
-            ] = self._get_container_property("readonlyRootFilesystem", False)
-            self.container_details["ulimits"] = self._get_container_property(
-                "ulimits", {}
-            )
-            self.container_details["vcpus"] = self._get_container_property("vcpus", 1)
-            self.container_details["memory"] = self._get_container_property(
-                "memory", 512
-            )
-            self.container_details["volumes"] = self._get_container_property(
-                "volumes", []
-            )
-            self.container_details["environment"] = self._get_container_property(
-                "environment", []
-            )
             self._start_attempt()
 
             # add host.docker.internal host on linux to emulate Mac + Windows behavior
@@ -744,8 +737,6 @@ def run(self) -> None:
                 self._log_backend.create_log_stream(log_group, stream_name)
                 self._log_backend.put_log_events(log_group, stream_name, logs)
 
-                self.container_details["logStreamName"] = self.log_stream_name
-
                 result = container.wait() or {}
                 exit_code = result.get("StatusCode", 0)
                 self.exit_code = exit_code


Test patch:
diff --git a/tests/test_batch_simple/test_batch_jobs.py b/tests/test_batch_simple/test_batch_jobs.py
--- a/tests/test_batch_simple/test_batch_jobs.py
+++ b/tests/test_batch_simple/test_batch_jobs.py
@@ -68,6 +68,8 @@ def test_submit_job_by_name():
     job["jobQueue"].should.equal(queue_arn)
     job["jobDefinition"].should.equal(job_definition_arn)
     job["status"].should.equal("SUCCEEDED")
+    job.should.contain("container")
+    job["container"].should.contain("command")
 
 
 @mock_batch_simple