Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object of class doublesecretagency\googlemaps\models\Address could not be converted to float #6

Closed
darylknight opened this issue Feb 24, 2021 · 11 comments

Comments

@darylknight
Copy link

darylknight commented Feb 24, 2021

Sorry this is going to be a bit vague; I can't work out exactly what's causing the issue.

I've just migrated this site from Smart Map to Google Maps. Generally went ok, but I'm seeing the same error in multiple places, basically whenever I try to interact with a Solspace Calendar event that contains an address field.

Trying to save a Solspace Calendar event that contains a Google Maps field saves the event, but it starts a task that fails immediately with the error:

Object of class doublesecretagency\googlemaps\models\Address could not be converted to float

This address field is not inside a matrix.

I previously had code working with Smart Map that combined Calendar Events with Entries, and showed the merged array on a map:

{# Get all events related to material through the matrix field #}
{% set events =
  craft.calendar.events({
    relatedTo: {
      targetElement: entry,
      field: 'siteRelatedMaterials'
    },
    rangeStart: now|date('Y-m-d'),
    rangeEnd: now|date_modify('+6 months'),
    orderBy: 'startDate asc'
  }).all()
%}

{# Get all sites related to material through the matrix field #}
{% set sites =
  craft.entries.section('sites').relatedTo({
    targetElement: entry,
    field: 'siteRelatedMaterials'
  }).orderBy(
    'title asc'
  ).all()
%}

{# Merged array - They both have an address field #}
{# {% set mergedLocations = events|merge(sites) %} #}

This template now also shows that same error, but doesn't tell me which line. I've tracked it down to trying to do ANYTHING with that Calendar Event model. Even if I try to {{ dump(event) }} it gives me that error message.

image

Additionally, trying to output any part of the address on the Calendar Event detail page gives the same error.

Any idea where to start? The fact that it happens inside the control panel makes me think it might be Calendar/Google Maps rather than just me.

@darylknight darylknight changed the title Updating Search Indexes Failed Object of class doublesecretagency\googlemaps\models\Address could not be converted to float Feb 24, 2021
@lindseydiloreto
Copy link
Collaborator

I just installed Solspace Calendar, and conducted a few basic tests...

Everything seems normal from what I can tell. I'm not getting any error messages when I save an Address field in a calendar Event. An Address field is just a normal fieldtype, so it should work just fine for all Element Types, both native & 3rd-party.

You may want to try nuking all of the composer files & cache. It could just be a glitchy install of one of the plugins.

And if that doesn't solve it, it could even be a bug in the Calendar plugin. Make sure you're running the latest version, then maybe contact their support channel if you're still having trouble.

@lindseydiloreto
Copy link
Collaborator

Btw, feel free to DM me on Discord if you want to work through it together. 👍

@darylknight
Copy link
Author

darylknight commented Feb 25, 2021

Thanks for looking into it Lindsey. I've tracked this down further and can replicate on a fresh install - it only happens when an event is set to Repeat. I think it means it's a bug with Calendar, but might need some back and forth with you (as I don't do PHP and have no idea what might cause this).

Looks like the error is specific to saving Calendar events which repeat, which contain Google Maps fields. Using the address field on it's own is fine. One-off events are fine, but as soon as I make an event recurring with an address field and try to save it, I get that error message when Craft tries to update search indexes again. Perhaps Calendar handles saving fields diferently if it's a recurring event.

I've filed a bug report with Calendar referencing this issue, but are you able to reproduce with a repeating event?

@lindseydiloreto
Copy link
Collaborator

Yeah, I'm seeing the same error in the queue jobs. You're right, it has to be a repeating event to trigger the error.

queue@2x

Feel free to drag me into a conversation with Solspace!

@darylknight
Copy link
Author

Just thought I'd check in again to see if there's anything you can do at your end about this, given that it was the migration from Smart Maps to Google Maps that caused the issue? I have a large site that I already migrated and updated, and is now missing address data all over the place while I wait to hear back from Solspace.

@lindseydiloreto
Copy link
Collaborator

lindseydiloreto commented Mar 4, 2021

Did you file an issue on the Calendars repo? It looks like they stay pretty on top of their Github issues. Probably worth starting a thread over there, since the bug is almost certainly on their end.

@darylknight
Copy link
Author

Ok - no worries, thank you. I have a support ticket open with them.

@gustavs-gutmanis
Copy link

Hi @lindseydiloreto, this issue is happening because Solspace Calendar is serializing all its values when a JSON representation is requested, this means that it's going through all its custom fields and is calling the normalizeValue(), which happens to be an doublesecretagency\googlemaps\models\Address instance.

I've made a Pull Request which introduces a check for this scenario. Could you please see if that's a valid solution to this issue?

@carlcs
Copy link
Contributor

carlcs commented Mar 12, 2021

I am having the same issue on multi-site Craft install. Error happens as soon as Craft tries to auto-save a draft and the entry is being propagated to the other sites and normalizeValue() is called in that process.

@carlcs
Copy link
Contributor

carlcs commented Mar 12, 2021

The changes made in the pull request fixes the issue for me. Thanks @gustavs-gutmanis

Update: while Gustav’s fix solved the issue with saving drafts, I noticed that I had another issue. When publishing a draft the address field got cleared for some reason. I tried @lindseydiloreto suggestion #14 (comment) which resolved that issue as well.

@lindseydiloreto
Copy link
Collaborator

Thanks for the update @carlcs! Good to hear how that patch is holding up against real-world testing. I've just pushed that fix live in v4.0.3.

And thanks @gustavs-gutmanis for helping track down the issue to make Calendar and Google Maps compatible! 🍺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants