Skip Navigation

[Closed] WordPress database error Duplicate entry in wp_toolset_maps_address_cache

This support ticket is created 3 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 3 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#1989149

Hi,

I'm seeing some database errors displayed (WP_DEBUG is turned on), when displaying maps. Typical error message is:

WordPress database error Duplicate entry 'eh48' for key 'PRIMARY' for query INSERT INTO wp_toolset_maps_address_cache ( `address_passed`, `address`, `point` ) VALUES ( 'eh48', 'Bathgate EH48, UK', ST_PointFromText('POINT(-3.668530 55.903599)') )

The postcode field is being used to provide the address, and clearly there are sometimes going to be duplicates.

My question is whether this error actually indicates a problem, or does it just mean that some addresses will not be cached (and so I can ignore the error)?

Thanks,

Chris

#1989577
WordPress database error Duplicate entry 'eh48' for key 'PRIMARY' for query INSERT INTO wp_toolset_maps_address_cache ( `address_passed`, `address`, `point` ) VALUES ( 'eh48', 'Bathgate EH48, UK', ST_PointFromText('POINT(-3.668530 55.903599)') )

The postcode field is being used to provide the address, and clearly there are sometimes going to be duplicates.
Hello, yes clearly there can be duplicates and the system is designed to handle those. Problems may occur in this case when unvalidated addresses are imported: https://toolset.com/forums/topic/search-page-not-showing-all-entries-and-duplicate-entry-error-in-error-log/
Were these problematic addresses imported from a 3rd-party data source?

When addresses are imported from 3rd-party resources, invariably some of these addresses contain similar information with different capitalization, for example "eh48" versus "EH48". In the normal Maps address creation workflow, an address is typed in the address field and the maps API presents some suggestions based on the entry. The User chooses one of those suggestions and the chosen version is saved and imported into the cache. The result is a consistent format for all addresses, e.g. the cached version is always EH48, never eh48, so this issue would never occur. What happens in the case of import is addresses are never validated, and eventually the system tries to add both versions to the cache. The database thinks that is a problem because primary keys disregard capitalization differences. The database will not allow you to create separate primary keys 'eh48' and 'EH48', and that is what Maps is trying to accomplish, hence the error here.

My question is whether this error actually indicates a problem, or does it just mean that some addresses will not be cached (and so I can ignore the error)?
Caching is required for some features like distance calculations, and also reduces the number of Google Maps API hits by caching the geocoded address. If you're using distance filters with Views, uncached addresses will never appear in those search results. If you're trying to display a map marker at an uncached address, the system will hit the Google Maps API each time you attempt to display a marker for that address, and each hit is considered when Google bills you for API usage. So no, I would not ignore this error.

We have an internal ticket in place to prevent this issue because another User experienced a similar problem after import, but I don't have a timeline available for the fix to be released. Assuming the issue in your case is indeed related to imported addresses, the ideal solution is to have your data source validate all addresses against the Maps API before giving them to you to import. If that is not possible, it's probably best to edit the posts containing addresses that are causing these error messages. Change the address and choose one of the address suggestions instead of the original value.

The topic ‘[Closed] WordPress database error Duplicate entry in wp_toolset_maps_address_cache’ is closed to new replies.