Repository navigation
Conversation
added 3 commits
September 18, 2026 11:33
cache.py created its process-wide RedisCacheBackend as a module global. The constructor reads LIGHTAPI_REDIS_URL, so the URL was fixed to whatever the environment held before `import lightapi`. Setting it later in code, or in a test, had no effect. _default_backend() builds the client on the first cache call and keeps it. get_cached, set_cached, invalidate_cache_prefix and _ping_redis keep their names and behaviour; invalidate_cache_prefix is documented for users and the tests patch the others. tests/test_cache_backend_lazy.py mocks redis.from_url and checks the late URL is used and that three cache calls share one client. Both tests fail with the eager global. Tests: 352 passed, 1 xfailed, 2 xpassed.
from_dict is a second way to build endpoint classes from data, next to the YAML loader. It has its own 137-line builder, its own rule for class names (/api/v1/items becomes ApiV1ItemsEndpoint here and ItemsEndpoint in YAML) and, until now, no test at all. One page of the docs mentions it; no example uses it. It keeps working and now emits a DeprecationWarning that names the two replacements. The docs page and the changelog say the same. tests/test_from_dict_deprecation.py checks the warning and that the app it builds still serves a POST. Tests: 354 passed, 1 xfailed, 2 xpassed.
This was referenced Sep 18, 2026
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #41 (then #40, #39, #38). Merge in order. This is the last one of the series.
What
Two small commits.
cache.pycreated its process-wideRedisCacheBackendas a module global. The constructor readsLIGHTAPI_REDIS_URL, so the URL was fixed to whatever the environment held beforeimport lightapi; setting it later, in code or in a test, was ignored._default_backend()now builds the client on the first cache call and keeps it.get_cached,set_cached,invalidate_cache_prefixand_ping_rediskeep their names and behaviour.LightApi.from_dictis deprecated, to be removed in 0.2.0. It still works and now emits aDeprecationWarningthat names the two replacements. It is a second way to build endpoint classes from data, with its own 137-line builder and its own class-naming rule, and it had no test. The docs page and the changelog say the same.What I decided not to do
This phase was planned as "remove global state". After checking each step against what the README and docs promise, most of it would break users for little gain:
ResponseCacheinstead of the module functions.invalidate_cache_prefixis documented for users, so a module-level client has to exist anyway. The tests patch these functions in 15 places, and injecting a fake would need an 11th constructor argument onLightApi. The lazy client fixes the one real defect.configobject thatJWTAuthenticationreads.lightapi.config.configlets an app set the JWT secret, algorithm and lifetime in code. Removing it breaks that path, and nothing is wrong with how it behaves today: the environment is read on each call.cls._session_managerfrom the endpoint class._get_engine()and_get_async_engine()read it, and the pagination reference shows users calling_get_async_engine(). Moving it to the instance would break any use of an endpoint outside a request.RedisCache,BaseCache,AuthenticationMiddleware,Responseand thelightapi.authmodule. The docs teach all of them:RedisCache18 times,Responsein 17 places plus the README and 3 examples,from lightapi.auth import16 times plus 4 in the README. Warning on what the tutorial tells people to type needs a decision about what the docs should recommend instead.Checks
All run on my machine. The test workflow does not run for PRs into
dev.pytest: 379 passed, 1 xfailed, 2 xpassed. That is 375 from refactor: give the big functions one job each (metaclass, register, Repository, YAML loader) #41 plus 4 new ones. The 375 includes the reflected-type fix merged up from refactor: replace type checks with polymorphism (handler, auth, pagination, table mapping) #40.redis.from_urland fail with the eager global. The deprecation test fails without the warning.lightapi/: 86% before, 88% now (2,094 statements, 246 missed).ruff check,ruff format --check,mypy: clean.The whole series, measured on
devand heredevlightapi/register, 270 linesload_from_dict, 137 lines (deprecated here)Not checked anywhere in the series: Postgres. Everything ran on SQLite and aiosqlite. #43 compares every response of this branch with the published 0.1.29; it found one regression, in #40, which is fixed there.