Cache Key now takes Git's Raw File URL Mask into account

Review Request #7928 — Created Jan. 30, 2016 and submitted

Information

Review Board
release-2.5.x

Reviewers

After initializing a Git repository and adding a bad Raw File URL Mask, the retrieved file is cached. After the Raw File URL Mask is changed to a valid one, the retrieved file is still from the cache because it does not take into consideration the new Raw File URL.

This was fixed by including the raw_file_url into the cache key for the functions: _make_file_exists_cache_key and _make_file_exists_cache_key. By including the raw_file_url into the cache key, the cache key will change whenever the raw file url is changed, such that it will not retrieve stale files from the cache. This change was included in reviewboard/scmtools/models.py.

Added unit tests to check that the cached copy of the file is grabbed when there are no changes to the raw_file_url and to check that a new file is retrieved when the raw_file_url changes.
Added unit test for get_file_exists() function.

Ran whole test suite- all tests pass.

Description From Last Updated

Single quotes for strings.

brenniebrennie

The two strings should line up, e.g.: ... = ('http://github.com...' 'reviewboard/....')

brenniebrennie

Single quotes for strings.

brenniebrennie

Col: 38 E128 continuation line under-indented for visual indent

reviewbotreviewbot

Col: 38 E128 continuation line under-indented for visual indent

reviewbotreviewbot

Col: 45 E128 continuation line under-indented for visual indent

reviewbotreviewbot

Col: 45 E128 continuation line under-indented for visual indent

reviewbotreviewbot

Col: 80 E501 line too long (83 > 79 characters)

reviewbotreviewbot

Col: 80 E501 line too long (81 > 79 characters)

reviewbotreviewbot

Col: 80 E501 line too long (81 > 79 characters)

reviewbotreviewbot

Col: 80 E501 line too long (89 > 79 characters)

reviewbotreviewbot

Col: 80 E501 line too long (81 > 79 characters)

reviewbotreviewbot

Col: 63 W291 trailing whitespace

reviewbotreviewbot

Col: 28 W291 trailing whitespace

reviewbotreviewbot

Col: 28 W291 trailing whitespace

reviewbotreviewbot

Col: 28 W291 trailing whitespace

reviewbotreviewbot

This can be None, so we need to normalize like above. (Same with the code below.) We're getting to the …

chipx86chipx86

How about: """Testing Repository.get_file re-fetches when raw file URL changes"""

chipx86chipx86

Here's a way to enhance the test and make it more thorough, self-explanatory, and future-proof: Return a fake result in …

chipx86chipx86

Col: 31 E251 unexpected spaces around keyword / parameter equals

reviewbotreviewbot

Col: 31 E251 unexpected spaces around keyword / parameter equals

reviewbotreviewbot

Col: 9 E265 block comment should start with '# '

reviewbotreviewbot

Col: 9 E265 block comment should start with '# '

reviewbotreviewbot

I'd like to see this have a few more comments, to explain exactly what the order of operations are. Comments …

daviddavid
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/scmtools/tests.py
        reviewboard/scmtools/models.py
    
    
  2. 
      
KS
brennie
  1. 
      
  2. reviewboard/scmtools/tests.py (Diff revision 1)
     
     
    Show all issues

    Single quotes for strings.

  3. reviewboard/scmtools/tests.py (Diff revision 1)
     
     
     
    Show all issues

    The two strings should line up, e.g.:

    ... = ('http://github.com...'
           'reviewboard/....')
    
  4. reviewboard/scmtools/tests.py (Diff revision 1)
     
     
    Show all issues

    Single quotes for strings.

  5. 
      
KS
KS
reviewbot
  1. Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/scmtools/tests.py
        reviewboard/scmtools/models.py
    
    
  2. reviewboard/scmtools/models.py (Diff revision 2)
     
     
    Show all issues
    Col: 38
     E128 continuation line under-indented for visual indent
    
  3. reviewboard/scmtools/models.py (Diff revision 2)
     
     
    Show all issues
    Col: 38
     E128 continuation line under-indented for visual indent
    
  4. reviewboard/scmtools/models.py (Diff revision 2)
     
     
    Show all issues
    Col: 45
     E128 continuation line under-indented for visual indent
    
  5. reviewboard/scmtools/models.py (Diff revision 2)
     
     
    Show all issues
    Col: 45
     E128 continuation line under-indented for visual indent
    
  6. reviewboard/scmtools/tests.py (Diff revision 2)
     
     
    Show all issues
    Col: 80
     E501 line too long (83 > 79 characters)
    
  7. reviewboard/scmtools/tests.py (Diff revision 2)
     
     
    Show all issues
    Col: 80
     E501 line too long (81 > 79 characters)
    
  8. reviewboard/scmtools/tests.py (Diff revision 2)
     
     
    Show all issues
    Col: 80
     E501 line too long (81 > 79 characters)
    
  9. reviewboard/scmtools/tests.py (Diff revision 2)
     
     
    Show all issues
    Col: 80
     E501 line too long (89 > 79 characters)
    
  10. reviewboard/scmtools/tests.py (Diff revision 2)
     
     
    Show all issues
    Col: 80
     E501 line too long (81 > 79 characters)
    
  11. 
      
KS
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/scmtools/tests.py
        reviewboard/scmtools/models.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/scmtools/tests.py
        reviewboard/scmtools/models.py
    
    
  2. reviewboard/scmtools/tests.py (Diff revision 3)
     
     
    Show all issues
    Col: 63
     W291 trailing whitespace
    
  3. reviewboard/scmtools/tests.py (Diff revision 3)
     
     
    Show all issues
    Col: 28
     W291 trailing whitespace
    
  4. reviewboard/scmtools/tests.py (Diff revision 3)
     
     
    Show all issues
    Col: 28
     W291 trailing whitespace
    
  5. reviewboard/scmtools/tests.py (Diff revision 3)
     
     
    Show all issues
    Col: 28
     W291 trailing whitespace
    
  6. 
      
KS
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/scmtools/tests.py
        reviewboard/scmtools/models.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/scmtools/tests.py
        reviewboard/scmtools/models.py
    
    
  2. 
      
chipx86
  1. Make sure to follow this guide on writing good summary/description content: https://www.reviewboard.org/docs/codebase/dev/writing-good-descriptions/

    I also want to see a unit test for get_file_exists().

    1. Should I test get_file_exists() to see how it responds to changes in the raw_file_url?

  2. reviewboard/scmtools/models.py (Diff revision 4)
     
     
    Show all issues

    This can be None, so we need to normalize like above. (Same with the code below.)

    We're getting to the point now, though, where this is going to hit the max line length. So how about:

    return 'file:...............' % (
        self.pk,
        urlquote(...),
        urlquote(...),
        ...
    )
    

    (One per line.)

    That'll help make this more readable. (Also, if you switch to single line quotes for this string while you're making this change, it'll help get our codebase more consistent.)

  3. reviewboard/scmtools/tests.py (Diff revision 4)
     
     
    Show all issues

    How about:

    """Testing Repository.get_file re-fetches when raw file URL changes"""
    
  4. reviewboard/scmtools/tests.py (Diff revision 4)
     
     
     
     
     
     
     
     
     
     
     
     
     
    Show all issues

    Here's a way to enhance the test and make it more thorough, self-explanatory, and future-proof:

    1. Return a fake result in your spy_on.
    2. Call and check the output.
    3. Change the fake result.
    4. Call and check that the output remains what it was before. (This ensures that we are in fact grabbing the cached copy, protecting us from test infrastructure failure or other weirdness.)
    5. Change the raw file URL.
    6. Call and check that we get the value from step 3.
  5. 
      
KS
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/scmtools/tests.py
        reviewboard/scmtools/models.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/scmtools/tests.py
        reviewboard/scmtools/models.py
    
    
  2. reviewboard/scmtools/tests.py (Diff revision 5)
     
     
    Show all issues
    Col: 31
     E251 unexpected spaces around keyword / parameter equals
    
  3. reviewboard/scmtools/tests.py (Diff revision 5)
     
     
    Show all issues
    Col: 31
     E251 unexpected spaces around keyword / parameter equals
    
  4. reviewboard/scmtools/tests.py (Diff revision 5)
     
     
    Show all issues
    Col: 9
     E265 block comment should start with '# '
    
  5. reviewboard/scmtools/tests.py (Diff revision 5)
     
     
    Show all issues
    Col: 9
     E265 block comment should start with '# '
    
  6. 
      
KS
reviewbot
  1. Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/scmtools/tests.py
        reviewboard/scmtools/models.py
    
    
  2. 
      
david
  1. 
      
  2. reviewboard/scmtools/tests.py (Diff revision 6)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Show all issues

    I'd like to see this have a few more comments, to explain exactly what the order of operations are. Comments should also start with a capital letter and end in a period.

  3. 
      
chipx86
  1. Hi Kevin,

    The info on what was wrong and how it was fixed should go in the description of the change. It shouldn't have its own headers, but just be a complete story. Take a look at the examples in that guide and you'll see what we expect. You can also dig into other commits by David and myself to see some other examples.

  2. 
      
KS
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/scmtools/tests.py
        reviewboard/scmtools/models.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/scmtools/tests.py
        reviewboard/scmtools/models.py
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
KS
Review request changed
Status:
Completed
Change Summary:
Pushed to release-2.5.x (7db43b4)