From dd9d4e01241e067aff4c49b95fde2cc5a5dba3e8 Mon Sep 17 00:00:00 2001
From: Arnaud Fontaine <arnaud.fontaine@nexedi.com>
Date: Thu, 4 Jul 2013 14:55:43 +0900
Subject: [PATCH] ZODB Components: Through Publisher, ExternalMethod
 getFuncCode() failed in development mode because there was a check whether
 Extension on FS should be reloaded even for Components.

---
 product/ERP5Type/patches/ExternalMethod.py          | 12 ++++++++++++
 .../ERP5Type/tests/testDynamicClassGeneration.py    | 13 +++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/product/ERP5Type/patches/ExternalMethod.py b/product/ERP5Type/patches/ExternalMethod.py
index e2a8d7a89c..ba3918b0a1 100644
--- a/product/ERP5Type/patches/ExternalMethod.py
+++ b/product/ERP5Type/patches/ExternalMethod.py
@@ -43,6 +43,18 @@ if 1:
 
     ExternalMethod.getFunction = getFunction
 
+    ExternalMethod_reloadIfChanged = ExternalMethod.reloadIfChanged
+    def reloadIfChanged(self):
+        try:
+            component_module = __import__(
+                'erp5.component.extension.' + self._module,
+                fromlist=['erp5.component.extension'],
+                level=0)
+        except ImportError:
+            return ExternalMethod_reloadIfChanged(self)
+
+    ExternalMethod.reloadIfChanged = reloadIfChanged
+
     def __call__(self, *args, **kw):
         """Call an ExternalMethod
 
diff --git a/product/ERP5Type/tests/testDynamicClassGeneration.py b/product/ERP5Type/tests/testDynamicClassGeneration.py
index 0a2d11eb1c..6e813ae12a 100644
--- a/product/ERP5Type/tests/testDynamicClassGeneration.py
+++ b/product/ERP5Type/tests/testDynamicClassGeneration.py
@@ -1834,6 +1834,19 @@ class TestZodbExtensionComponent(_TestZodbComponent):
     external_method = self.getPortal().TestExternalMethod
     self.assertEqual(external_method(), 42)
 
+    # Check that the External Method returns expected result through Publisher
+    # with or without DevelopmentMode
+    path = '%s/TestExternalMethod' % self.portal.getId()
+    self.assertEqual(self.publish(path).getBody(), '42')
+
+    import Globals
+    previous_development_mode = Globals.DevelopmentMode
+    Globals.DevelopmentMode = not Globals.DevelopmentMode
+    try:
+      self.assertEqual(self.publish(path).getBody(), '42')
+    finally:
+      Globals.DevelopmentMode = previous_development_mode
+
     # Add a Python Script with the External Method defined above and check
     # that it returns 42
     from Products.PythonScripts.PythonScript import manage_addPythonScript
-- 
2.30.9