statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.68k stars 503 forks source link

Asset Relationship Field breaks in antlers after statamic 5 update #10411

Closed danielml01 closed 1 month ago

danielml01 commented 1 month ago

Bug description

in asset relationship fields, asset ids stored as container::filepath generate an error when called to display in antlers after updgrade to statamic 5 (they still work in the control panel) Temporarily can be fixed by going to the entry with the field and saving without changing anything. This changes the stored id from container::filepath to just filepath.

How to reproduce

create an entry that has an asset relationship field. Select an asset and save the entry. Edit yaml file for the entry and format the stored value to container::filepath (as it was previously) save yaml file in the antler, display any value from the related asset > this will generate an error in statamic 5

Logs

Found 1 error while validating the input provided for the GetObject operation: [Key] expected string length to be >= 1, but found string length of 0

Environment

Environment
Application Name: REDACTED
Laravel Version: 10.48.12
PHP Version: 8.1.20
Composer Version: 2.5.8
Environment: dev
Debug Mode: OFF
URL: REDACTED
Maintenance Mode: OFF

Cache
Config: CACHED
Events: NOT CACHED
Routes: CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: redis
Database: mysql
Logs: errorlog
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 12
Sites: 1
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.7.2 PRO

Statamic Addons
aryehraber/statamic-logbook: 3.3.0
jacksleight/statamic-bard-texstyle: 3.2.2
kadegray/statamic-country-and-region-fieldtypes: 1.2.4
rias/statamic-color-swatches: 2.3.0
simonridley/tracking-code-manager: 1.0.2
statamic/eloquent-driver: 4.2.0
stillat/relationships: 2.2.0
teamddm/aws-transcode: dev-main
teamddm/cp-password-expires: dev-main
teamddm/statamic-mixpanel: dev-main
teamddm/statamic-pdf-thumbnailer: dev-main
webographen/statamic-admin-log: 1.1.0

Statamic Eloquent Driver
Asset Containers: file
Assets: eloquent
Blueprints: file
Collection Trees: file
Collections: file
Entries: file
Forms: file
Global Sets: file
Global Variables: file
Navigation Trees: file
Navigations: file
Revisions: file
Taxonomies: file
Terms: file
Tokens: file

Installation

Starter Kit using via CLI

Additional details

No response

duncanmcclean commented 1 month ago

Found 1 error while validating the input provided for the GetObject operation: [Key] expected string length to be >= 1, but found string length of 0

That doesn't look like an error from Statamic. Are you using S3 (or similar)?

duncanmcclean commented 1 month ago

Also, what does your Antlers template look like?

danielml01 commented 1 month ago

Thank you for following up so quickly. We recently moved to using the eloquent driver for our assets meta. We're using a mysql database using statamic's native eloquent driver.

The relevant code that's breaking involves an asset relationship field called "thumbnail" `{{ if thumbnail }} {{ thumbnail }}

{{ alt }}
                    {{ /thumbnail }}
                {{ else }}
                    <img src="/cover_images/1443109462_Screen-Shot-2015-09-24-at-11.43.50-AM.png" alt="REDACTED logo" height="462" width="834"/>
                {{ /if }}`
jasonvarga commented 1 month ago

Was this site ever on Statamic v2?

danielml01 commented 1 month ago

No it was not. We started in statamic 4

jasonvarga commented 1 month ago

I don't really understand how you ended up with asset ids in your data rather than just paths. We've saved paths into asset fields since v3.

duncanmcclean commented 1 month ago

Like Jason mentioned, I'm not sure how you managed to end up with Asset IDs (eg. container::path), instead of simply the path, since we haven't saved the IDs for a long time.

If possible, I'd recommend updating asset references to remove the container:: part since the fieldtype no longer supports it.