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

running the tests deletes the default user #2407

Closed
ltalirz opened this issue Jan 21, 2019 · 14 comments
Closed

running the tests deletes the default user #2407

ltalirz opened this issue Jan 21, 2019 · 14 comments

Comments

@ltalirz
Copy link
Member

ltalirz commented Jan 21, 2019

I encountered the following error while trying to run my first WorkChain on the new provenance_redesign branch, python 2.7.15:

  File "/Users/leopold/Personal/Postdoc-MARVEL/repos/aiida/aiida_rmq/aiida/orm/implementation/django/node.py", line 127, in __init__
    user = orm.User.objects.get_default().backend_entity
AttributeError: 'NoneType' object has no attribute 'backend_entity'

This is in a profile that was migrated to the current provenance_redesign branch (not created from scratch).

To me, this raises a few questions:

  • how is it possible that my profile does not have a default user?
  • should a profile with no default user be allowed? I.e. should orm.User.objects.get_default() be allowed to return None or should it raise an exception?
  • if you don't have a default user, how do you add one? I tried adding a new user via verdi user (which worked) but, apparently, this is not enough. How do I make it the default one?

Perhaps @giovannipizzi could comment?

@giovannipizzi
Copy link
Member

I think you copied only part of the error.
Could you tell us if there is any mention of the default user in the config file (.aiida/config.json)? (default_user_email inside a profile section)

What does verdi profile list say about the default user?

Probably it's possible that there is no way of setting a default user and a new command should be added to verdi user for simplicity (even if I think that probably one could achieve what you want to do with verdi setup but I didn't try).

@ltalirz
Copy link
Member Author

ltalirz commented Jan 22, 2019

I think you copied only part of the error.

thanks for pointing this out - fixed!

Could you tell us if there is any mention of the default user in the config file (.aiida/config.json)?

Indeed, there is a default user specified but it doesn't show up in verdi user list

What does verdi profile list say about the default user?

I guess you mean verdi profile show. It correctly shows the information stored in the config file (but the user doesn't seem to exist in the DB).

Probably it's possible that there is no way of setting a default user and a new command should be added to verdi user for simplicity

Either to verdi user or, perhaps, rather to verdi profile, since one is actually setting the default user for a profile.

@giovannipizzi
Copy link
Member

I see, so the problem is that the user is not in the DB, right? Do you know how this happened?

@ltalirz
Copy link
Member Author

ltalirz commented Jan 22, 2019

so the problem is that the user is not in the DB, right? Do you know how this happened?

I don't really know - but it might be my fault in some way. Let's for the moment assume it is my fault.

I would still say that we need to decide whether having no default user is allowed or not. Currently, part of the codebase seems to assume that it cannot happen (while it can), which would mean we should raise an exception, ideally with instructions on how to make a user the default one.

@ltalirz
Copy link
Member Author

ltalirz commented Jan 22, 2019

Just mentioning that @waychal had exactly the same problem (no default user, no users showing up in verdi user list).

Furthermore, I had the user that I previously configured via verdi user configure disappear from verdi user list after rebooting my system.

@ltalirz
Copy link
Member Author

ltalirz commented Jan 25, 2019

Just happened again to me as well: the users seem to be randomly deleted - i.e. I'm still on the same profile but now verdi user list is empty.

@giovannipizzi
Copy link
Member

That's really weird...
could you check if there are places in the code where a delete call on the user is called, to see if it's inadvertently triggered as a side-effect of some other call?

@ltalirz
Copy link
Member Author

ltalirz commented Jan 31, 2019

Not sure whether this is related but on PR #2421 I'm getting an error (on python2.7 only)
DETAIL: Key (user_id)=(21) is not present in table "db_dbuser".:
https://travis-ci.org/aiidateam/aiida_core/jobs/486559586#L3074

@ltalirz ltalirz changed the title no default user users randomly deleted Jan 31, 2019
@ltalirz
Copy link
Member Author

ltalirz commented Feb 13, 2019

One of the problems might have been that I was running on a test database (and might have been running tests).
Still, I have the feeling this did not happen in previous AiiDA versions (and it is annoying, since it prevents you from keeping to do tests on the test database)

@giovannipizzi
Copy link
Member

I have the feeling this happened in your PR #2214 (but with the commit by @muhrin), where before there was something like

         # We create the user only once:		
         # Otherwise, get_automatic_user() will fail when the		
         # user is recreated because it caches the user!		
         # In any case, store it in self.user though		
         try:		
             self.user = DbUser.objects.get(email=get_configured_user_email())		
         except ObjectDoesNotExist:		
             self.user = DbUser.objects.create_user(get_configured_user_email(), 'fakepwd')

and now

DbUser.objects.all().delete()  # pylint: disable=no-member

I think also the deleted comment is quite explicative. Is it possible? I don't know though if @muhrin moved the logic somewhere else

@ltalirz
Copy link
Member Author

ltalirz commented Feb 14, 2019

I think the first code you pasted is not related but the second one in clean_db is:
https://github.com/aiidateam/aiida_core/pull/2214/files#diff-d85c6625843bfeca5bb54998de77fe55L102

Before:

DbUser.objects.exclude(email=get_configured_user_email()).delete()

After:

DbUser.objects.all().delete() 

Indeed this would mean that the tests could still pass (since a new default user will be created on demand), but running the tests will always result in deletion of the default user.

@ltalirz ltalirz changed the title users randomly deleted running the tests deletes the default user Feb 14, 2019
@ltalirz
Copy link
Member Author

ltalirz commented Mar 1, 2019

To summarize:

I personally still find it annoying not to have a default user in the database because it means you can't do anything in the shell without setting up the user first.
Furthermore, I find it inconsistent that after creating a test database via verdi quicksetup there will be a default user that will be deleted the first time you run a test.
This confused both @waychal and me.

Anyhow, I can also see the argument by spyros. Feel free to close

@ltalirz
Copy link
Member Author

ltalirz commented Mar 1, 2019

Perhaps, the larger question here is what a user is supposed to be able to do with a test profile.

If the policy is that you cannot do anything with a test profile other than run the tests, then I think there is actually no need to set it up as a regular profile using verdi quicksetup.
Instead we could use something like this
https://github.com/aiidateam/aiida_core/blob/da6bb4d1657cdf742adb4ef9fb1739e08404320d/aiida/backends/tests/manage/external/test_postgres.py#L33-L36
and create the temporary profile on the fly.

@ltalirz
Copy link
Member Author

ltalirz commented May 4, 2019

this last comment will be addressed in #2771, so this can be closed

@ltalirz ltalirz closed this as completed May 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants