How does discourse get full names of imported users?

AI-generated summary

The discussion explores how Discourse generates full names (user.name) for imported users when only email and username are provided. mrded notes that despite having no full name data, Discourse assigns names during import, even for users with non-English characters. gerhard explains that the system first attempts to derive a name from the email address using suggest_name, and if the original username contains invalid characters (like Chinese characters), it uses the original username as the name. mrded confirms this behavior, showing that the original username is used for user.name when it’s invalid, and a sanitized version is used for user.username. The process relies on the official import script’s logic in base.rb.

We have a database of users to be migrated into Discourse. All these users have only emails and random usernames.

After a migration, I noticed that most of the users got user.name fields, which are real full names.

First of all, I thought that Discours tries to generate a name from an email. But then I found some users with Chinese characters, and they emails and usernames are not even similar to the generated full name.

Again, we don’t have a full name, Discourse generates it itself and I don’t understand how. We only have an email and a username, which is random.

The question is, how does discourse generate a user.name? Thanks.

I’m assuming you are using one of the official import scripts or at least based your import script on the base importer.

At first it tries to guess the name from the email address:

And, if the original username was changed during the import (e.g. because it contained Chinese characters, which aren’t allowed in usernames) then it will set the name to the original username.

Yes, I use the official import script, forgot to mention that scripts/import_scripts/base.rb.

And import looks like:

  create_users(query) do |row|
    { 
      id: row['id'], 
      username: row['username'], 
      email: row['email'], 
      created_at: Time.zone.at(row['created_at'])
    }
  end

Ok, I get it. If I import a user:

{
  username: 'hel&^$lo',
  email: 'foo@bar.com'
}

It puts hel&^$lo into a user.name and generates new user.username without forbiden letters.