#4457 Fix has_home_tool() implementation

v1.0.0
closed
nobody
General
nobody
2015-08-20
2012-06-27
No

Neighborhood.has_home_tool() checks by mount point. We need to check tool type, not mount point.

Related

Tickets: #4457

Discussion

  • Dave Brondsema

    Dave Brondsema - 2012-06-27
    • labels: 42cc --> 42cc, performance
     
  • Dave Brondsema

    Dave Brondsema - 2012-06-27

    This will have the affect of avoiding project queries in the 2nd half of the nbhd index() method.

     
  • Yaroslav Luzin - 2012-06-28
    • status: open --> in-progress
     
  • Yaroslav Luzin - 2012-06-28

    created #95: [#4457] Fix has_home_tool() implementation (1cp)

     

    Related

    Tickets: #4457

  • Yaroslav Luzin - 2012-07-03

    closed #95 and pushed changes into 42cc_4457

    • status: in-progress --> code-review
     
  • Dave Brondsema

    Dave Brondsema - 2012-07-03

    This works and matches the pattern of def app_config() but since this method will be called frequently (every nbhd root request), I think we should change it to use self.app_configs which is a list that is already loaded into memory.

     
  • Dave Brondsema

    Dave Brondsema - 2012-07-03
    • status: code-review --> in-progress
     
  • Yaroslav Luzin - 2012-07-06

    created #107: [#4457] Use self.app_configs instead of quering database each time (1cp)

     

    Related

    Tickets: #4457

  • Igor Bondarenko - 2012-07-09

    I made the following changes:

    --- a/Allura/allura/model/project.py
    +++ b/Allura/allura/model/project.py
    @@ -515,9 +515,9 @@ def app_config(self, mount_point):
                     'options.mount_point':mount_point}).first()
    
         def app_config_by_tool_type(self, tool_type):
    -        return AppConfig.query.find({
    -                'project_id': self._id,
    -                'tool_name': tool_type}).first()
    +        for ac in self.app_configs:
    +            if ac.tool_name == tool_type:
    +                return ac
    

    but got failed test:

    ======================================================================
    ERROR: allura.tests.test_commands.test_update_neighborhood
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/var/tmp/buildenv/1a26a3f8009f89f489415fb1c0b257ece5282961/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
        self.test(*self.arg)
      File "/home/deploy/buildbot/slave2/full/build/Allura/allura/tests/test_commands.py", line 124, in test_update_neighborhood
        cmd.command()
      File "/home/deploy/buildbot/slave2/full/build/Allura/allura/command/create_neighborhood.py", line 69, in command
        p.install_app('home', 'home', 'Home', ordinal=0)
      File "/home/deploy/buildbot/slave2/full/build/Allura/allura/model/project.py", line 472, in install_app
        'Mount point "%s" is already in use' % mount_point)
    ToolError: Mount point "home" is already in use
    

    After some debugging I found out that results of self.app_configs and querying the database directly differs:

    ipdb> for ac in p.app_configs: print ac.project_id, ac.tool_name, ac.options['ordinal']
    4ffaa7828fd0922bc2000286 admin 2
    4ffaa7828fd0922bc2000286 Wiki 1
    
    ipdb> for ac in M.AppConfig.query.find({'project_id': p._id}): print ac.project_id, ac.tool_name, ac.options['ordinal']
    4ffaa7828fd0922bc2000286 admin 2
    4ffaa7828fd0922bc2000286 home 0
    4ffaa7828fd0922bc2000286 Wiki 1
    

    Seems like self.app_configs contains cached result, but I can't find a way to update it properly.
    Could you point me in the right direction?

     
  • Dave Brondsema

    Dave Brondsema - 2012-07-09
    • status: in-progress --> closed
    • size: --> 0.5
    • milestone: forge-backlog --> forge-jul-13
     
  • Dave Brondsema

    Dave Brondsema - 2012-07-09

    I've encountered the same issue once before. I wish install_app() would refresh the app_configs list, but I don't think there is a way to do that, and its possible to work around it fairly well.

    There were two parts of the problem:

    1. In the test, cmd.run() runs the command, and cmd.command() is unnecessary. It runs it again.
    2. If you close the session after the command is run, and before checking the result, then the Project object is queried anew, so it gets the latest values for everything.

    I went ahead and committed [58e0e2] using your changes, plus those 2 fixes. I've pushed it on dev, so you can look at it.

     

Log in to post a comment.