Service not found exception

Created on 19 January 2022, over 2 years ago
Updated 22 May 2023, about 1 year ago

Problem/Motivation

Call to sqlsrv.views.date_sql in custom programming code causes white screen error page with this specific message:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "sqlsrv.views.date_sql". Did you mean this: "views.date_sql"? in Drupal\Component\DependencyInjection\Container->get() (line 156 of /var/www/web/core/lib/Drupal/Component/DependencyInjection/Container.php).

Steps to reproduce

Upgrade Drupal core to version 9.3.3 and Drupal driver for SQL Server and SQL Azure (775804) to version 4.3.1

Rolling Drupal driver for SQL Server and SQL Azure (775804) back to version 4.3.0 fixes the problem.

πŸ› Bug report
Status

Fixed

Version

4.3

Component

Schema handling

Created by

πŸ‡ΊπŸ‡ΈUnited States scotthreha

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 8
    last update about 1 year ago
    Waiting for branch to pass
  • πŸ‡ΊπŸ‡ΈUnited States Maather AlJabri

    When upgrading the sqlsrv module to a version higher than 4.3.0 (i.e 4.3.1), sqlsrv.views.date_sql in sqlsrv.services.yml is set to private which means it cannot be accessed directly from the container at runtime. I changed the value in the public parameter from 'false' to 'true' in sqlsrv.services.yml and was able to fix the error. I attached a patch with the fix.

  • Status changed to RTBC about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom pstewart

    @Beakerboy is correct in #4 πŸ› Service not found exception Fixed , in that the intended approach for backend overridable services is that you would ask for the overridable service from the container (views.date_sql in this case) and you would get the correct backend version of the service corresponding to the preferred default backend configured in your site's services.yml, e.g.

    parameters:
      default_backend: sqlsrv
    

    This is presumably why the core backend implementations are marked private - they're only intended to ever be used via the backend override mechanism rather than injected directly at runtime. However this doesn't take into account use cases where the database driver is used to access a secondary database, where defining the default_backend in that way is not applicable (if the primary database is Mysql then the default backend still needs to be mysql).

    Allowing the sqlsrv.views.date_sql to be public is therefore necessary to facilitate these kinds of use cases, so Maather's patch in #6 πŸ› Service not found exception Fixed is the correct fix.

  • Status changed to Fixed about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom pstewart
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024