# How does discourse get full names of imported users?

**URL:** https://meta.discourse.org/t/how-does-discourse-get-full-names-of-imported-users/92916
**Category:** Development
**Created:** [23 juli 2018 om 09:54 UTC](https://meta.discourse.org/t/how-does-discourse-get-full-names-of-imported-users/92916 "2018-07-23T09:54:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mrded](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrded/32/62438_2.png) [@mrded](https://meta.discourse.org/u/mrded)
#### Post date: [23 juli 2018 om 09:54 UTC](https://meta.discourse.org/t/how-does-discourse-get-full-names-of-imported-users/92916/1 "2018-07-23T09:54:51Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [23 juli 2018 om 10:06 UTC](https://meta.discourse.org/t/how-does-discourse-get-full-names-of-imported-users/92916/2 "2018-07-23T10:06:11Z")

</div>

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:

> <https://github.com/discourse/discourse/blob/84ab825e41126c1954b714b245f45e3072878dea/script/import_scripts/base.rb#L299-L299>

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.

> <https://github.com/discourse/discourse/blob/84ab825e41126c1954b714b245f45e3072878dea/script/import_scripts/base.rb#L315-L315>

---

<div class="post-metadata">

### Author: ![mrded](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrded/32/62438_2.png) [@mrded](https://meta.discourse.org/u/mrded)
#### Post date: [23 juli 2018 om 10:14 UTC](https://meta.discourse.org/t/how-does-discourse-get-full-names-of-imported-users/92916/3 "2018-07-23T10:14:30Z")

</div>

> [@gerhard](#):
>
> ser.suggest\_name(opts[:email]) unless opts[:name

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

And import looks like:

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

```

---

<div class="post-metadata">

### Author: ![mrded](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mrded/32/62438_2.png) [@mrded](https://meta.discourse.org/u/mrded)
#### Post date: [23 juli 2018 om 10:30 UTC](https://meta.discourse.org/t/how-does-discourse-get-full-names-of-imported-users/92916/5 "2018-07-23T10:30:14Z")

</div>

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

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

```

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