# Export to CSV and Excel creates contact duplicates

**URL:** <https://forum.mautic.org/t/export-to-csv-and-excel-creates-contact-duplicates/22647>\
**Category:** Development\
**Created:** [February 9, 2022, 4:40pm UTC](https://forum.mautic.org/t/export-to-csv-and-excel-creates-contact-duplicates/22647 "2022-02-09T16:40:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![adiux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/adiux/32/5793_2.png) [@adiux](https://forum.mautic.org/u/adiux)\
**Post date:** [February 9, 2022, 4:40pm UTC](https://forum.mautic.org/t/export-to-csv-and-excel-creates-contact-duplicates/22647/1 "2022-02-09T16:40:55Z")

</div>

I noticed that there is a problem with exporting 11000 of contacts to CSV or Excel. Some contacts are duplicated and others are not. The total amount of contacts in the export is the expected 11000.

So far I noticed that the later contacts (with higher ids) are more affected.

It’s a problem with the latest v3 branch and with the latest 4.x branch.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [February 9, 2022, 4:48pm UTC](https://forum.mautic.org/t/export-to-csv-and-excel-creates-contact-duplicates/22647/2 "2022-02-09T16:48:01Z")

</div>

Can you clarify if you mean export from reports or export from the contact list? The export from reports can be done via a command which has much higher time and memory limits than a HTTP request. The export feature from the contact list does not have an option to do it on a background so it will run on large number of records until the memory or time limit is hit for the HTTP request. You can increase those limits on server if that’s what you want to do.

I’d recommend to go with the scheduled reports where the report is generated in the background and sent to your email:

> **[Reports | Mautic](https://docs.mautic.org/en/reports#scheduling-reports)**
>
> . Highly customizable reports can be generated through Mautic's Report menu.Data Sources. Choose the data source appropriate to the report you want. Each data source has a different set of available columns, filters and graphs.. Types of data sources...

---

<div class="post-metadata">

**Author:** ![adiux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/adiux/32/5793_2.png) [@adiux](https://forum.mautic.org/u/adiux)\
**Post date:** [February 9, 2022, 4:53pm UTC](https://forum.mautic.org/t/export-to-csv-and-excel-creates-contact-duplicates/22647/3 "2022-02-09T16:53:11Z")

</div>

Thanks @escopecz for that insight. I will try the way via report as well.

However, it would be great if the export via contacts works too:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/4/40a18c3aba19255d60907fcf269ff2202ad2a8f7.png)  
Or at least shows a message that it didn’t work.

Since I get a CSV, just with duplicate entries, I don’t think it is a problem with the memory limit or the timeout?

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/c/c0f20be04e84bf4c2ec99941c5765d6a759633a2.png)

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [February 9, 2022, 5:12pm UTC](https://forum.mautic.org/t/export-to-csv-and-excel-creates-contact-duplicates/22647/4 "2022-02-09T17:12:04Z")

</div>

The duplicates looks like a bug. But I’m not able to reproduce it. When I export my contacts from the contact list I get only unique IDs. Please try to find steps to replicate the duplicates. Do you have another Mautic instance where it also exports duplicates? There must be something unique on that instance.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [February 9, 2022, 5:21pm UTC](https://forum.mautic.org/t/export-to-csv-and-excel-creates-contact-duplicates/22647/5 "2022-02-09T17:21:01Z")

</div>

Hi,  
Do you have multiple keys / unique identifiers in this instance?  
They seem to have the same ID, which is unique…

---

<div class="post-metadata">

**Author:** ![adiux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/adiux/32/5793_2.png) [@adiux](https://forum.mautic.org/u/adiux)\
**Post date:** [February 10, 2022, 7:39am UTC](https://forum.mautic.org/t/export-to-csv-and-excel-creates-contact-duplicates/22647/6 "2022-02-10T07:39:29Z")

</div>

It looks like the problem is the sorting of the database query. When the query sorts by `last_activity` we have the problem. When the query sorts by `id` everything is ok. Sorting by `last_active` is used by default.

---

<div class="post-metadata">

**Author:** ![adiux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/adiux/32/5793_2.png) [@adiux](https://forum.mautic.org/u/adiux)\
**Post date:** [February 10, 2022, 7:42am UTC](https://forum.mautic.org/t/export-to-csv-and-excel-creates-contact-duplicates/22647/7 "2022-02-10T07:42:14Z")

</div>

We replicated it on 4 different instances. But always with the same database. So far I did only see it with contact lists \>10k. But we have a test sample of 10k contacts now that we plan to import and export again in a fresh Mautic instance. Will update you soon.

---

<div class="post-metadata">

**Author:** ![volha](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/volha/32/6820_2.png) [@volha](https://forum.mautic.org/u/volha)\
**Post date:** [February 10, 2022, 12:02pm UTC](https://forum.mautic.org/t/export-to-csv-and-excel-creates-contact-duplicates/22647/8 "2022-02-10T12:02:09Z")

</div>

Hi,

Seems the `OFFSET` clause doesn’t work well when the table is sorted by a column containing all `NULL` values. We get this issue when there are more than 10,000 client records in the DB.

Could you please try the next steps to reproduce it

1. Import the mock data (10,000 or more)
2. Open the contact list
3. Order by the field with no value (e.g. last\_activity if data was imported)
4. Export to CVS
5. Open file, sort by id
6. There are twice
7. Open the contact list again
8. Order by id
9. Export to CVS
10. Open file, sort by id
11. Everything ok

I can send mock clients to import.

---

<div class="post-metadata">

**Author:** ![adiux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/adiux/32/5793_2.png) [@adiux](https://forum.mautic.org/u/adiux)\
**Post date:** [February 17, 2022, 9:16am UTC](https://forum.mautic.org/t/export-to-csv-and-excel-creates-contact-duplicates/22647/9 "2022-02-17T09:16:21Z")

</div>

Related PR [Export to CSV and Excel creates contact duplicates by volha-pivavarchyk · Pull Request #10849 · mautic/mautic · GitHub](https://github.com/mautic/mautic/pull/10849)
