lint: Ban general use of user_profile.save().

This often can cause minor caching problems.

Obviously, it'd be better if we had access to the AST and thus could
do this rule for UserProfile objects in general.
This commit is contained in:
Tim Abbott
2017-11-20 10:52:10 -08:00
parent 432c9d3449
commit 25ddba99f6
3 changed files with 12 additions and 3 deletions

View File

@@ -241,6 +241,14 @@ def build_custom_checkers(by_lang):
'description': '@login_required is unsupported; use @zulip_login_required',
'good_lines': ['@zulip_login_required', '# foo @login_required'],
'bad_lines': ['@login_required', ' @login_required']},
{'pattern': '^user_profile[.]save[(][)]',
'description': 'Always pass update_fields when saving user_profile objects',
'exclude_line': set([
('zerver/lib/actions.py', "user_profile.save() # Can't use update_fields because of how the foreign key works."),
]),
'exclude': set(['zerver/tests', 'zerver/lib/create_user.py']),
'good_lines': ['user_profile.save(update_fields=["pointer"])'],
'bad_lines': ['user_profile.save()']},
{'pattern': '^[^"]*"[^"]*"%\(',
'description': 'Missing space around "%"',
'good_lines': ['"%s" % ("foo")', '"%s" % (foo)'],

View File

@@ -2529,7 +2529,7 @@ def check_change_full_name(user_profile, full_name_raw, acting_user):
def do_change_bot_owner(user_profile, bot_owner, acting_user):
# type: (UserProfile, UserProfile, UserProfile) -> None
user_profile.bot_owner = bot_owner
user_profile.save()
user_profile.save() # Can't use update_fields because of how the foreign key works.
event_time = timezone_now()
RealmAuditLog.objects.create(realm=user_profile.realm, acting_user=acting_user,
modified_user=user_profile, event_type='bot_owner_changed',

View File

@@ -88,9 +88,10 @@ def generate_all_emails(request):
user_profile = get_user(registered_email, realm)
result = client.get(url)
assert result.status_code == 200
# Reset the email value
# Reset the email value so we can run this again
user_profile.email = registered_email
user_profile.save()
user_profile.save(update_fields=['email'])
# Follow up day1 day2 emails
enqueue_welcome_emails(user_profile)