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

[3.x]: Deprecation Warnings tab isn't telling me where to find this specific deprecated code #11597

Closed
mikesnoeren opened this issue Jul 14, 2022 · 4 comments

Comments

@mikesnoeren
Copy link

What happened?

Description

Somewhere in my code there was a line that was causing a Deprecation Warning. The Deprecation warning tab in the CMS is not telling me where this code is located. I therefore had to go through all my code to comment it out file by file and then line by line to see when the error would stop generating.. But I tracked it down! Can this be fixed?

Note: Other deprecation warnings were working correctly, even ones where I was using the same deprecated code as in the example provided below..

Warning:

Looping through element queries directly has been deprecated. Use all() to fetch the query results before looping over them.

Code causing warning:

{# This loop caused the warning, it was missing `.all()` before the `batch` function  #}
{% for items in block.features|batch(3) %} 
  ...
{% endfor %}

Steps to reproduce

  1. Use the code provided above
  2. Check Deprecation Warning tab in CMS

Expected behavior

The Deprecation Warning should tell me where to find the deprecated code

Actual behavior

It doesn't tell me where to find the deprecated code

Craft CMS version

Craft CMS 3.7.48

PHP version

7.3.33

Operating system and version

Linux 5.10.104-linuxkit

Database type and version

MySQL 5.7.38

Image driver and version

Imagick 3.6.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

  • Express Forms 1.1.2
  • Kint 1.0.0
  • MatrixMate 1.4.5
  • Navigation 1.4.27
  • Redactor 2.10.10
  • SEO 3.7.4
  • Super Table 2.7.2
  • SVG Placeholder 1.0.3
  • Typed link field 1.0.25
brandonkelly added a commit that referenced this issue Jul 16, 2022
@brandonkelly
Copy link
Member

Thank you for reporting that! Fixed now for the next release.

@bartrylant
Copy link
Contributor

Checking if this is the same error or another error. This message:

Treating element queries as arrays has been deprecated. Use exists() to determine if an element query will yield any results, or all() to fetch the results.

Now gives a line in a compiled template file as source.

@brandonkelly
Copy link
Member

brandonkelly commented Jul 24, 2022

@bartrylant Craft 3.7.48 fixed a bug where treating an element query as an array wasn’t always getting a deprecation warning (8fa998c).

The bug described in this issue is that some of those deprecation warnings were missing a source file/line altogether, when using the |batch filter. I’ve separately improved the deprecation warnings so they will show the source Twig template file & line rather than the compiled template, for the next release (cc2ee65).

That said, we’ve also decided to bring back support for treating element queries as arrays in Craft 4.2, which is imminent (#11625). We will remove the deprecation warning in Craft 3 once that’s out. So it’s safe to ignore.

@brandonkelly
Copy link
Member

brandonkelly commented Jul 26, 2022

Craft 3.7.49 was released earlier today with the fix for this, and 3.7.50 is also out now, which removes the deprecation warning entirely, as it’s no longer a concern when upgrading to Craft 4 (#11625).

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

No branches or pull requests

3 participants