Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't crash if user doesn't exist in mailcow #133

Merged
merged 3 commits into from
Apr 11, 2024
Merged

Conversation

missytake
Copy link
Contributor

Fixes this annoying crash:

2024-04-11T12:26:09.426000639Z Traceback (most recent call last):                                                                                                                                                                            
2024-04-11T12:26:09.426011588Z   File "/usr/lib/python3.10/site-packages/mailadm/bot.py", line 270, in main                                                                                                                                  
2024-04-11T12:26:09.426021251Z     for logmsg in prune(mailadm_db).get("message"):                                                                                                                                                           
2024-04-11T12:26:09.426030978Z   File "/usr/lib/python3.10/site-packages/mailadm/commands.py", line 70, in prune                                                                                                                             
2024-04-11T12:26:09.426042245Z     expired_users = conn.get_expired_users(sysdate)                                                                                                                                                           
2024-04-11T12:26:09.426048044Z   File "/usr/lib/python3.10/site-packages/mailadm/conn.py", line 278, in get_expired_users                                                                                                                    
2024-04-11T12:26:09.426062633Z     last_login = self.get_mailcow_connection().get_user(user.addr).last_login                                                                                                                                 
2024-04-11T12:26:09.426068696Z AttributeError: 'NoneType' object has no attribute 'last_login'                                                                                                                                               

@@ -274,7 +274,11 @@ def get_expired_users(self, sysdate):
if user.ttl < mailadm.util.parse_expiry_code("27d"):
expired_users.append(user)
continue
last_login = self.get_mailcow_connection().get_user(user.addr).last_login
mc_user = self.get_mailcow_connection().get_user(user.addr)
if not mc_user:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more idiomatic/precise to do "if mc_user is None" usually but no biggie.

@hpk42
Copy link
Contributor

hpk42 commented Apr 11, 2024

CI tests fail

@missytake
Copy link
Contributor Author

CI tests fail

yes, we deprecated ci.testrun.org and don't have a mailcow for that right now, unless we want to use testrun.org for that (rather not). dc.develcow.de would also make sense. hm.

@missytake missytake merged commit 048762e into master Apr 11, 2024
1 check passed
@missytake missytake deleted the fix-prune branch April 11, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants