async def test_startup_doesnt_write_txn_contextvar_in_main_task(command_arguments): with pytest.raises(TransactionNotFound): get_current_transaction() async def run(args, settings, app): with pytest.raises(TransactionNotFound): get_current_transaction() settings = testing.get_settings() command = Command(command_arguments) command.run = run app = command.make_app(settings) await command._run_async(app, settings) with pytest.raises(TransactionNotFound): get_current_transaction()
async def _query(self, context: IResource, query: ParsedQueryInfo, unrestricted: bool = False): sql, arguments = self.build_query(context, query, ["id", "zoid", "json"], unrestricted=unrestricted) txn = get_current_transaction() conn = await txn.get_connection() results = [] fullobjects = query["fullobjects"] container = find_container(context) if container is None: raise ContainerNotFound() try: context_url = get_object_url(container) request = get_current_request() except RequestNotFound: context_url = get_content_path(container) request = None logger.debug(f"Running search:\n{sql}\n{arguments}") async with txn.lock: records = await conn.fetch(sql, *arguments) for record in records: data = json.loads(record["json"]) if fullobjects and request is not None and txn is not None: # Get Object obj = await txn.get(data["uuid"]) # Serialize object view = DefaultGET(obj, request) result = await view() else: result = self.load_meatdata(query, data) result["@name"] = record["id"] result["@uid"] = record["zoid"] result["@id"] = data[ "@absolute_url"] = context_url + data["path"] results.append(result) # also do count... total = len(results) if total >= query["size"] or query["_from"] != 0: sql, arguments = self.build_count_query(context, query, unrestricted=unrestricted) logger.debug(f"Running search:\n{sql}\n{arguments}") async with txn.lock: records = await conn.fetch(sql, *arguments) total = records[0]["count"] return {"items": results, "items_total": total}
async def reindex_all_content(self, container, security=False): """ recursively go through all content to reindex jsonb... """ data = {"count": 0, "transaction": None, "transactions": 0, "tm": get_current_transaction()._manager} try: data["table_name"] = data["tm"]._storage._objects_table_name except AttributeError: # Not supported DB return data["transaction"] = await data["tm"].begin() container.__txn__ = data["transaction"] await self._process_object(container, data) if IFolder.providedBy(container): await self._process_folder(container, data) await data["tm"].commit(txn=data["transaction"])
def __init__( self, utility, context, response=noop_response, force=False, log_details=False, memory_tracking=False, request=None, bulk_size=40, full=False, reindex_security=False, mapping_only=False, index_manager=None, children_only=False, lookup_index=False, cache=True, ): self.utility = utility self.context = context self.response = response self.force = force self.full = full self.log_details = log_details self.memory_tracking = memory_tracking self.bulk_size = bulk_size self.reindex_security = reindex_security self.children_only = children_only self.lookup_index = lookup_index if mapping_only and full: raise Exception("Can not do a full reindex and a mapping only migration") self.mapping_only = mapping_only self.txn = get_current_transaction() if not cache: # make sure that we don't cache requests... self.txn._cache = DummyCache(self.txn) self.request = request self.container = get_current_container() self.conn = utility.get_connection() if index_manager is None: self.index_manager = get_adapter(self.container, IIndexManager) else: self.index_manager = index_manager self.user = get_authenticated_user() self.policy = get_security_policy(self.user) self.indexer = Indexer() self.batch = {} self.indexed = 0 self.processed = 0 self.missing = [] self.orphaned = [] self.existing = [] self.errors = [] self.mapping_diff = {} self.start_time = self.index_start_time = time.time() self.reindex_futures = [] self.status = "started" self.active_task_id = None self.copied_docs = 0 self.work_index_name = None self.sub_indexes = []
async def run(args, settings, app): with pytest.raises(TransactionNotFound): get_current_transaction()