#13165 closed defect (fixed)
tracd incorrectly says "needs to be upgraded" if an exception is raised from needs_upgrade()
Reported by: | Jun Omae | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Milestone: | 1.3.4 |
Component: | general | Version: | 1.3dev |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: |
Fixed "Environment needs to be upgraded" message when an exception is raised from plugin. |
||
API Changes: | |||
Internal Changes: |
Description
Environment.needs_upgrade()
raised a TypeError
because installed plugin has incompatible method with Trac 1.3.x:
TypeError: environment_needs_upgrade() takes exactly 2 arguments (1 given)
When the error is raised, I get "needs to be upgraded" from tracd
. It's incorrect, because the Trac environment is up-to-date.
Trac Error TracError: The Trac Environment needs to be upgraded. Run: trac-admin "/home/jun66j5/var/trac/1.3-sqlite" upgrade
It seems the behavior is introduced in [15939] (#12680).
I consider that we should raise a TracError
with Unable to check for upgrade message when an exception is raised from needs_upgrade()
:
-
trac/env.py
diff --git a/trac/env.py b/trac/env.py index bf3fbb11c..0a6b868a9 100644
a b def open_environment(env_path=None, use_cache=False): 857 857 CacheManager(env).reset_metadata() 858 858 else: 859 859 env = Environment(env_path) 860 needs_upgrade = True861 860 try: 862 861 needs_upgrade = env.needs_upgrade() 862 except TracError as e: 863 env.log.error("Exception caught while checking for upgrade: %s", 864 exception_to_unicode(e)) 865 raise 863 866 except Exception as e: # e.g. no database connection 864 867 env.log.error("Exception caught while checking for upgrade: %s", 865 868 exception_to_unicode(e, traceback=True)) 866 if needs_upgrade: 867 raise TracError(_('The Trac Environment needs to be upgraded. ' 868 'Run:\n\n trac-admin "%(path)s" upgrade', 869 path=env_path)) 869 raise TracError(_("Unable to check for upgrade: %(err)s", 870 err=exception_to_unicode(e))) 871 else: 872 if needs_upgrade: 873 raise TracError(_('The Trac Environment needs to be upgraded. ' 874 'Run:\n\n trac-admin "%(path)s" upgrade', 875 path=env_path)) 870 876 871 877 return env 872 878
After the patch, tracd
says in this case:
Trac Error TracError: Unable to check for upgrade: TypeError: environment_needs_upgrade() takes exactly 2 arguments (1 given)}
Attachments (0)
Change History (6)
comment:1 by , 6 years ago
comment:2 by , 6 years ago
Agreed. I reworked the patch based on your suggestion.
Revised patch:
-
trac/env.py
diff --git a/trac/env.py b/trac/env.py index bf3fbb11c..865c93def 100644
a b class Environment(Component, ComponentManager): 745 745 def needs_upgrade(self): 746 746 """Return whether the environment needs to be upgraded.""" 747 747 for participant in self.setup_participants: 748 with self.component_guard(participant, reraise=True): 749 if participant.environment_needs_upgrade(): 750 self.log.warning( 751 "Component %s requires environment upgrade", 752 participant) 753 return True 748 try: 749 with self.component_guard(participant, reraise=True): 750 if participant.environment_needs_upgrade(): 751 self.log.warning( 752 "Component %s requires environment upgrade", 753 participant) 754 return True 755 except Exception as e: 756 raise TracError(_("Unable to check for upgrade of " 757 "%(module)s.%(name)s: %(err)s", 758 module=participant.__class__.__module__, 759 name=participant.__class__.__name__, 760 err=exception_to_unicode(e))) 754 761 return False 755 762 756 763 def upgrade(self, backup=False, backup_dest=None): … … def open_environment(env_path=None, use_cache=False): 857 864 CacheManager(env).reset_metadata() 858 865 else: 859 866 env = Environment(env_path) 860 needs_upgrade = True861 867 try: 862 868 needs_upgrade = env.needs_upgrade() 869 except TracError as e: 870 env.log.error("Exception caught while checking for upgrade: %s", 871 exception_to_unicode(e)) 872 raise 863 873 except Exception as e: # e.g. no database connection 864 874 env.log.error("Exception caught while checking for upgrade: %s", 865 875 exception_to_unicode(e, traceback=True)) 866 if needs_upgrade: 867 raise TracError(_('The Trac Environment needs to be upgraded. ' 868 'Run:\n\n trac-admin "%(path)s" upgrade', 869 path=env_path)) 876 raise 877 else: 878 if needs_upgrade: 879 raise TracError(_('The Trac Environment needs to be upgraded. ' 880 'Run:\n\n trac-admin "%(path)s" upgrade', 881 path=env_path)) 870 882 871 883 return env 872 884
tracd
message after the revised patch:
Trac Error TracError: Unable to check for upgrade of tracdragdrop.web_ui.TracDragDropModule: TypeError: environment_needs_upgrade() takes exactly 2 arguments (1 given)
Logging after the revised patch:
2019-05-28 21:45:16,920 Trac[env] ERROR: Component <Component tracdragdrop.web_ui.TracDragDropModule> failed with Traceback (most recent call last): File "/home/jun66j5/src/tracdev/git/trac/env.py", line 387, in component_guard yield File "/home/jun66j5/src/tracdev/git/trac/env.py", line 750, in needs_upgrade if participant.environment_needs_upgrade(): TypeError: environment_needs_upgrade() takes exactly 2 arguments (1 given) 2019-05-28 21:45:16,924 Trac[env] ERROR: Exception caught while checking for upgrade: TracError: Unable to check for upgrade of tracdragdrop.web_ui.TracDragDropModule: TypeError: environment_needs_upgrade() takes exactly 2 arguments (1 given)
comment:4 by , 5 years ago
Release Notes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:5 by , 5 years ago
Owner: | set to |
---|
comment:6 by , 5 years ago
Release Notes: | modified (diff) |
---|
Good idea, but reporting which plugin raised such an error seems also very useful in this case (so that one could disable it if needed).