MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_shard_id_event

Method test_shard_id_event

test/ext/test_horizontal_shard.py:530–567  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

528 eq_(t.city, tokyo.city)
529
530 def test_shard_id_event(self):
531 # this test is kind of important, it's testing that
532 # when the load event is emitted for an ORM result,
533 # the context is set up in the state that is expected.
534 # prior to 1.4, we were changing a single context in place,
535 # as we would join result sets by fully evaluating and concatenating.
536 # in 1.4 onwards we return a Result that has not run for each
537 # individual result yet, so each one has its own context that
538 # is a shallow copy from the original.
539
540 canary = []
541
542 def load(instance, ctx):
543 canary.append(ctx.bind_arguments["shard_id"])
544
545 event.listen(WeatherLocation, "load", load)
546 sess = self._fixture_data()
547
548 tokyo = ( # noqa
549 sess.query(WeatherLocation)
550 .filter_by(city="Tokyo")
551 .set_shard("asia")
552 .one()
553 )
554
555 sess.query(WeatherLocation).all()
556 eq_(
557 canary,
558 [
559 "asia",
560 "north_america",
561 "north_america",
562 "europe",
563 "europe",
564 "south_america",
565 "south_america",
566 ],
567 )
568
569 def test_baked_mix(self):
570 sess = self._fixture_data()

Callers

nothing calls this directly

Calls 8

_fixture_dataMethod · 0.95
eq_Function · 0.90
set_shardMethod · 0.80
listenMethod · 0.45
oneMethod · 0.45
filter_byMethod · 0.45
queryMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected