testcontainers / testcontainers/testcontainers-python

Bug: MSSQL (SqlServerContainer) ignores some parameters

Open
#736 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.3k
Forks
386
Avg merge
4h 40m
Merged PRs (30d)
1

Description

Describe the bug

When running the SqlServerContainer, in this example with the image mcr.microsoft.com/mssql/server:2022-CU12-ubuntu-22.04, some parameters have no effect on the actual database and lead to failures. It seems like they are just not respected.

To Reproduce

import sqlalchemy
from testcontainers.mssql import SqlServerContainer

def test_showcase_bug():
    with SqlServerContainer(image="mcr.microsoft.com/mssql/server:2022-CU12-ubuntu-22.04", username="dummy") as mssql:
        engine = sqlalchemy.create_engine(mssql.get_connection_url()) # this includes the username "dummy" now.
        print(mssql.get_connection_url())
        with engine.begin() as connection:
            result = connection.execute(sqlalchemy.text("select @@VERSION"))

It loads a while. When looking at the database logs, it prints:

2024-11-14 10:39:43.81 Logon       Error: 18456, Severity: 14, State: 5.
2024-11-14 10:39:43.81 Logon       Login failed for user 'dummy'. Reason: Could not find a login matching the name provided. [CLIENT: 172.17.0.3]

Same thing for other parameters, for example db_name.

Runtime environment

Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of testcontainers-python you are using? You can run the following commands to get the relevant information.

Windows 11
Python 3.11.9
testcontainers 4.8.2
sqlalchemy 2.0.36
pymssql 2.3.1

Thanks for your work!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the SqlServerContainer implementation and reproduce the example with the specified MSSQL image, username, and db_name parameters. Trace how these parameters are passed to the container and connection URL, then verify that the running database applies them and that the example no longer fails authentication.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python, sqlalchemy
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.