Repository: ESMValGroup/ESMValCore

Issue:
Bug in fix for FGOALS-g2
The fix for FGOALS-g2 (CMIP5) does not work on `fx` variable, since it attempts to fix the time coordinate, which is not defined in `fx` variables:
```
        for cube in cubes:
            time = cube.coord('time')
            time.units = Unit(time.units.name, time.units.calendar)
```

Discussion:

Patch:
diff --git a/esmvalcore/cmor/_fixes/cmip5/fgoals_g2.py b/esmvalcore/cmor/_fixes/cmip5/fgoals_g2.py
index 8811d3953..23c032abb 100644
--- a/esmvalcore/cmor/_fixes/cmip5/fgoals_g2.py
+++ b/esmvalcore/cmor/_fixes/cmip5/fgoals_g2.py
@@ -1,6 +1,7 @@
 
 """Fix FGOALS-g2 model."""
 from cf_units import Unit
+from iris.exceptions import CoordinateNotFoundError
 
 from ..fix import Fix
 
@@ -24,6 +25,10 @@ class AllVars(Fix):
 
         """
         for cube in cubes:
-            time = cube.coord('time')
-            time.units = Unit(time.units.name, time.units.calendar)
+            try:
+                time = cube.coord('time')
+            except CoordinateNotFoundError:
+                pass
+            else:
+                time.units = Unit(time.units.name, time.units.calendar)
         return cubes


Test patch:
diff --git a/tests/integration/cmor/_fixes/cmip5/test_fgoals_g2.py b/tests/integration/cmor/_fixes/cmip5/test_fgoals_g2.py
index 805a2bf1b..a17eeeb29 100644
--- a/tests/integration/cmor/_fixes/cmip5/test_fgoals_g2.py
+++ b/tests/integration/cmor/_fixes/cmip5/test_fgoals_g2.py
@@ -36,3 +36,8 @@ class TestAll(unittest.TestCase):
         self.assertEqual(time.units.origin,
                          'day since 1-01-01 00:00:00.000000')
         self.assertEqual(time.units.calendar, 'gregorian')
+
+    def test_fix_metadata_dont_gail_if_not_time(self):
+        """Test calendar fix."""
+        self.cube.remove_coord('time')
+        self.fix.fix_metadata([self.cube])