e-valuation / EvaP

a university course evaluation system written in Python using Django
Other
96 stars 146 forks source link

Creating Superuser fails on a fresh install #2204

Open Keridos opened 1 month ago

Keridos commented 1 month ago

Using docker provider. Start up a fresh docker instance via Vagrant. Try the create superuser command. It asks for login email and password. Enter credentials. It then crashes due to the postgresql having a constraint that first name of a user must not be null.

janno42 commented 1 month ago

Will look into that. Please use the "evap" user as described in step 3 of the installation section in the readme for now: https://github.com/e-valuation/EvaP?tab=readme-ov-file#installation-for-development

Kakadus commented 1 month ago

I also noticed the problem after loading custom data which did not have a superuser.

@richardebeling pointed out that REQUIRED_FIELDS should fix it :+1:

richardebeling commented 1 month ago

@Keridos do you want to open a pull request that adds the first_name and last_name fields to the REQUIRED_FIELDS class attribute? I would appreciate it! :)

The relevant lines should be https://github.com/e-valuation/EvaP/blob/a1af82ac3886999e4cecbf4fb88266373270eea8/evap/evaluation/models.py#L1657 and https://github.com/e-valuation/EvaP/blob/a1af82ac3886999e4cecbf4fb88266373270eea8/evap/evaluation/models.py#L1735

Keridos commented 1 month ago

As I got no experience with django projects I have a question there: I can add the fields first_name_given and last_name to the required fields. But does django know that when calling create_superuser that first_name is actually passed from first_name_given?. The variable names in there are a bit confusing.

richardebeling commented 1 month ago

Ah, good point, I think we didn't handle that the way django intends in #1903 (see the change here).

My understanding of the django docs on custom user profile managers is that the argument for create_user and create_superuser probably should also be renamed from first_name to first_name_given. Then, I'd expect that having first_name_given in the REQUIRED_FIELDS works.

(background information regarding the variable naming: Since #1903, we distinguish between first_name_given, the first name that the person legally has and may not have control over, and first_name_chosen, the preferred first name that the person would like to be addressed by)