Skip to content

Commit ec3174e

Browse files
fastapi-sqlalchemy-pg-catalog: parameterize README + SQL_ECHO env knob
Addresses two Copilot review nits on #102: * README.md: the local-repro snippet hardcoded `--container-name pg-catalog-repro-app`, but the compose file uses `${APP_CONTAINER:-pg-catalog-repro-app}` so a user who overrides APP_CONTAINER (e.g. to isolate concurrent runs) would have keploy point at a non-existent container. Both keploy invocations now thread `${APP_CONTAINER:-pg-catalog-repro-app}` so they pick up the same env override compose sees. Also switched the deprecated camelCase `--apiTimeout`/`--disableMockUpload` to the kebab forms the v3 CLI actually registers (`--api-timeout`; mock-upload flag dropped — not registered on v3-dev `test`). * main.py: SQL echo was unconditional. It is INTENTIONALLY on by default for this sample (the whole point is to surface SQLAlchemy's pg_class probe + create_all behaviour in the app log so a reader can correlate it with the keploy agent log), but the noise is real for unrelated investigations. Gated behind SQL_ECHO env var with a comment explaining why it's on by default. Signed-off-by: Akash Kumar <meakash7902@gmail.com>
1 parent 4becdde commit ec3174e

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

fastapi-sqlalchemy-pg-catalog/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,23 @@ bash flow.sh
4343
docker compose down -v
4444

4545
# Record
46+
# Both keploy invocations below pass `--container-name "${APP_CONTAINER:-pg-catalog-repro-app}"`
47+
# so they track whatever the compose file is rendering for the app
48+
# service. If you've overridden APP_CONTAINER (e.g. to isolate
49+
# concurrent runs), the same export reaches both keploy and compose.
4650
( bash flow.sh > flow-record.log 2>&1 ) &
4751
sudo -E keploy record \
4852
-c "docker compose -f docker-compose.yml up" \
49-
--container-name pg-catalog-repro-app \
53+
--container-name "${APP_CONTAINER:-pg-catalog-repro-app}" \
5054
--cmd-type docker-compose \
5155
--record-timer 60s
5256

5357
# Replay (pre-fix: FAILS with "no recorded invocation matched" on CREATE TABLE)
5458
sudo -E keploy test \
5559
-c "docker compose -f docker-compose.yml up" \
56-
--container-name pg-catalog-repro-app \
60+
--container-name "${APP_CONTAINER:-pg-catalog-repro-app}" \
5761
--cmd-type docker-compose \
58-
--apiTimeout 120 --delay 15 --disableMockUpload
62+
--api-timeout 120 --delay 15
5963
```
6064

6165
## Layout

fastapi-sqlalchemy-pg-catalog/app/main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
log = logging.getLogger("repro")
3434

3535
DATABASE_URL = os.environ["DATABASE_URL"]
36+
# SQL echo is INTENTIONALLY on by default — this is a sample for
37+
# demonstrating the dispatcher's simple-Query catalog path, and seeing
38+
# the actual SQLAlchemy queries (pg_catalog.version, pg_class probe,
39+
# CREATE TABLE on miss) in the app log is the load-bearing observation
40+
# that lets a reader correlate the keploy agent log with what the app
41+
# is doing. The trade-off: SQLAlchemy logs every statement at INFO,
42+
# which is verbose in normal operation. Override SQL_ECHO=0 to quiet
43+
# it down for unrelated investigations.
44+
SQL_ECHO = os.environ.get("SQL_ECHO", "1") != "0"
3645

3746
Base = declarative_base()
3847

@@ -44,7 +53,7 @@ class Project(Base):
4453
name = Column(String(100), nullable=False)
4554

4655

47-
engine = create_engine(DATABASE_URL, echo=True, future=True)
56+
engine = create_engine(DATABASE_URL, echo=SQL_ECHO, future=True)
4857

4958

5059
@asynccontextmanager

0 commit comments

Comments
 (0)