Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue during postprovision : #20

Open
aantonellims opened this issue Dec 19, 2024 · 2 comments
Open

issue during postprovision : #20

aantonellims opened this issue Dec 19, 2024 · 2 comments

Comments

@aantonellims
Copy link

aantonellims commented Dec 19, 2024

Hello Team,

I've well deployed the semantic reranker first, copy the .env, updated the below variable :

  • AZURE_ML_SCORING_ENDPOINT
  • AZURE_ML_ENDPOINT_KEY

Then, after a few errors on the setup_postgres_legal_database.py (because of the path), I'm facing an issue during post deployment step :

PS C:\Users\aantonelli\source\repos\graphrag-legalcases-postgres> azd up
? Environment 'postgresql-graph' does not exist, would you like to create it? (Y/n)

ERROR: loading environment: prompting to create environment 'postgresql-graph': interrupt
? Environment 'pgsql-graph' does not exist, would you like to create it? Yes
? Select an Azure Subscription to use: 37. xxxxxxxxxxxxxxxxxxxxxx)
? Select an Azure location to use: 31. (Europe) Sweden Central (swedencentral)

Packaging services (azd package)

(✓) Done: Packaging service web

Provisioning Azure resources (azd provision)
Provisioning Azure resources can take some time.

Subscription: MCAPS-Hybrid-REQ-55446-2023-aantonelli (0bf9ccf7-89ed-455b-8c5a-97c0a85fa27e)
Location: Sweden Central

You can view detailed progress in the Azure Portal:
https://portal.azure.com/#view/HubsExtension/DeploymentDetailsBlade/~/overview/id/%2Fsubscriptions%2Fxxxxxxxx%2Fproviders%2FMicrosoft.Resources%2Fdeployments%2Fpgsql-graph-1734628119

(✓) Done: Resource group: pgsql-graph-rg (3.689s)
(✓) Done: Log Analytics workspace: pgsql-graph-di3wracltt6ge-loganalytics (2.796s)
(✓) Done: Application Insights: pgsql-graph-di3wracltt6ge-appinsights (5.758s)
(✓) Done: Azure OpenAI: pgsql-graph-di3wracltt6ge-openai (28.369s)
(✓) Done: Portal dashboard: pgsql-graph-di3wracltt6ge-appinsights-dashboard (1.467s)
(✓) Done: Azure AI Services Model Deployment: pgsql-graph-di3wracltt6ge-openai/gpt-35-turbo-16k (1.077s)
(✓) Done: Azure AI Services Model Deployment: pgsql-graph-di3wracltt6ge-openai/text-embedding-3-small (2.155s)
(✓) Done: Container Registry: pgsqlgraphdi3wracltt6geregistry (22.216s)
(✓) Done: Container Apps Environment: pgsql-graph-di3wracltt6ge-containerapps-env (35.882s)
(✓) Done: Azure Database for PostgreSQL flexible server: pgsql-graph-di3wracltt6ge-postgresql (4m10.669s)
(✓) Done: Container App: pgsql-graph-di3wrac-ca (30.76s)
current sys.path: ['C:\Users\aantonelli\source\repos\graphrag-legalcases-postgres\src\backend\fastapi_app', 'C:\Python311\python311.zip', 'C:\Python311\DLLs', 'C:\Python311\Lib', 'C:\Python311', 'C:\Users\aantonelli\AppData\Roaming\Python\Python311\site-packages', 'C:\Users\aantonelli\AppData\Roaming\Python\Python311\site-packages\win32', 'C:\Users\aantonelli\AppData\Roaming\Python\Python311\site-packages\win32\lib', 'C:\Users\aantonelli\AppData\Roaming\Python\Python311\site-packages\Pythonwin', 'C:\Python311\Lib\site-packages', 'C:\Users\aantonelli\source\repos\autogen_v04\autogen\python\packages\autogen-magentic-one\src', 'C:\Python311\Lib\site-packages\vboxapi-1.0-py3.11.egg', 'C:\Users\aantonelli\source\repos\graphrag-legalcases-postgres\src\backend']
content of backend_dir: ['.dockerignore', 'Dockerfile', 'entrypoint.sh', 'fastapi_app', 'package-lock.json', 'pyproject.toml', 'static']
INFO:legalcaseapp:Enabling azure_ai extension...
INFO:legalcaseapp:Enabling the pgvector extension for Postgres...
INFO:legalcaseapp:Setting Azure ML endpoint and API key...
INFO:legalcaseapp:Creating semantic_relevance function...
INFO:legalcaseapp:Creating database tables and indexes...
INFO:legalcaseapp:Enabling the Apache AGE extension for Postgres...
INFO:legalcaseapp:Database extension and tables created successfully.
current sys.path: ['C:\Users\aantonelli\source\repos\graphrag-legalcases-postgres\src\backend\fastapi_app', 'C:\Python311\python311.zip', 'C:\Python311\DLLs', 'C:\Python311\Lib', 'C:\Python311', 'C:\Users\aantonelli\AppData\Roaming\Python\Python311\site-packages', 'C:\Users\aantonelli\AppData\Roaming\Python\Python311\site-packages\win32', 'C:\Users\aantonelli\AppData\Roaming\Python\Python311\site-packages\win32\lib', 'C:\Users\aantonelli\AppData\Roaming\Python\Python311\site-packages\Pythonwin', 'C:\Python311\Lib\site-packages', 'C:\Users\aantonelli\source\repos\autogen_v04\autogen\python\packages\autogen-magentic-one\src', 'C:\Python311\Lib\site-packages\vboxapi-1.0-py3.11.egg', 'C:\Users\aantonelli\source\repos\graphrag-legalcases-postgres\src\backend']
content of backend_dir: ['.dockerignore', 'Dockerfile', 'entrypoint.sh', 'fastapi_app', 'package-lock.json', 'pyproject.toml', 'static']
INFO:ragapp:Authenticating to Azure Database for PostgreSQL using Azure Identity...
INFO:ragapp:Updating password token for Azure Database for PostgreSQL
INFO:ragapp:Creating a PostgreSQL role for identity pgsql-graph-di3wracltt6ge-id-web
INFO:ragapp:Granting permissions to pgsql-graph-di3wracltt6ge-id-web
INFO:ragapp:Role created successfully.
current sys.path: ['C:\Users\aantonelli\source\repos\graphrag-legalcases-postgres\src\backend\fastapi_app', 'C:\Python311\python311.zip', 'C:\Python311\DLLs', 'C:\Python311\Lib', 'C:\Python311', 'C:\Users\aantonelli\AppData\Roaming\Python\Python311\site-packages', 'C:\Users\aantonelli\AppData\Roaming\Python\Python311\site-packages\win32', 'C:\Users\aantonelli\AppData\Roaming\Python\Python311\site-packages\win32\lib', 'C:\Users\aantonelli\AppData\Roaming\Python\Python311\site-packages\Pythonwin', 'C:\Python311\Lib\site-packages', 'C:\Users\aantonelli\source\repos\autogen_v04\autogen\python\packages\autogen-magentic-one\src', 'C:\Python311\Lib\site-packages\vboxapi-1.0-py3.11.egg', 'C:\Users\aantonelli\source\repos\graphrag-legalcases-postgres\src\backend']
content of backend_dir: ['.dockerignore', 'Dockerfile', 'entrypoint.sh', 'fastapi_app', 'package-lock.json', 'pyproject.toml', 'static']
INFO:ragapp:Authenticating to Azure Database for PostgreSQL using Azure Identity...
INFO:azure.identity._internal.decorators:AzureDeveloperCliCredential.get_token succeeded
INFO:legalcaseapp:Starting data seeding from C:\Users\aantonelli\source\repos\graphrag-legalcases-postgres\data\cases_final.csv using parameterized INSERT statements.
INFO:ragapp:Updating password token for Azure Database for PostgreSQL
INFO:azure.identity._internal.decorators:AzureDeveloperCliCredential.get_token succeeded
INFO:legalcaseapp:gold_dataset table initialized successfully.
INFO:legalcaseapp:100 rows inserted and committed in batch.
INFO:legalcaseapp:100 rows inserted and committed in batch.
INFO:legalcaseapp:100 rows inserted and committed in batch.
INFO:legalcaseapp:100 rows inserted and committed in batch.
INFO:legalcaseapp:10 rows inserted and committed in batch.
INFO:legalcaseapp:Data seeding completed successfully.
INFO:legalcaseapp:Function get_vector_semantic_graphrag_optimized defined successfully.
INFO:legalcaseapp:Function initialize_age_extension defined successfully.
INFO:legalcaseapp:Function create_case_in_case_graph defined successfully.
INFO:legalcaseapp:Function create_case_link_in_case_graph defined successfully.
INFO:legalcaseapp:case_graph database is created successfully.
Traceback (most recent call last):
File "C:\Python311\Lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 546, in _prepare_and_execute
self._rows = await prepared_stmt.fetch(*parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\asyncpg\prepared_stmt.py", line 176, in fetch
data = await self.__bind_execute(args, 0, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\asyncpg\prepared_stmt.py", line 267, in __bind_execute
data, status, _ = await self.__do_execute(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\asyncpg\prepared_stmt.py", line 256, in __do_execute
return await executor(protocol)
^^^^^^^^^^^^^^^^^^^^^^^^
File "asyncpg\protocol\protocol.pyx", line 206, in bind_execute
asyncpg.exceptions.UndefinedObjectError: role "None" does not exist

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Python311\Lib\site-packages\sqlalchemy\engine\base.py", line 1969, in _exec_single_context
self.dialect.do_execute(
File "C:\Python311\Lib\site-packages\sqlalchemy\engine\default.py", line 922, in do_execute
cursor.execute(statement, parameters)
File "C:\Python311\Lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 580, in execute
self.adapt_connection.await(
File "C:\Python311\Lib\site-packages\sqlalchemy\util_concurrency_py3k.py", line 130, in await_only
return current.driver.switch(awaitable) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\sqlalchemy\util_concurrency_py3k.py", line 195, in greenlet_spawn
value = await result
^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 558, in _prepare_and_execute
self._handle_exception(error)
File "C:\Python311\Lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 509, in _handle_exception
self._adapt_connection._handle_exception(error)
File "C:\Python311\Lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 797, in _handle_exception
raise translated_error from error
sqlalchemy.dialects.postgresql.asyncpg.AsyncAdapt_asyncpg_dbapi.ProgrammingError: <class 'asyncpg.exceptions.UndefinedObjectError'>: role "None" does not exist

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\aantonelli\source\repos\graphrag-legalcases-postgres\src\backend\fastapi_app\setup_postgres_legal_seeddata.py", line 537, in
asyncio.run(main())
File "C:\Python311\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\asyncio\base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\aantonelli\source\repos\graphrag-legalcases-postgres\src\backend\fastapi_app\setup_postgres_legal_seeddata.py", line 528, in main
await seed_data_from_csv(engine, args.app_identity_name)
File "C:\Users\aantonelli\source\repos\graphrag-legalcases-postgres\src\backend\fastapi_app\setup_postgres_legal_seeddata.py", line 114, in seed_data_from_csv
await ingest_cases_to_graph_from_postgresql(session, app_identity_name)
File "C:\Users\aantonelli\source\repos\graphrag-legalcases-postgres\src\backend\fastapi_app\setup_postgres_legal_seeddata.py", line 178, in ingest_cases_to_graph_from_postgresql
await session.execute(text(f'GRANT ALL ON SCHEMA case_graph TO "{app_identity_name}";'))
File "C:\Python311\Lib\site-packages\sqlalchemy\ext\asyncio\session.py", line 455, in execute
result = await greenlet_spawn(
^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\sqlalchemy\util_concurrency_py3k.py", line 200, in greenlet_spawn
result = context.throw(*sys.exc_info())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\sqlalchemy\orm\session.py", line 2308, in execute
return self._execute_internal(
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\sqlalchemy\orm\session.py", line 2199, in _execute_internal
result = conn.execute(
^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\sqlalchemy\engine\base.py", line 1416, in execute
return meth(
^^^^^
File "C:\Python311\Lib\site-packages\sqlalchemy\sql\elements.py", line 517, in _execute_on_connection
return connection._execute_clauseelement(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\sqlalchemy\engine\base.py", line 1639, in _execute_clauseelement
ret = self._execute_context(
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\sqlalchemy\engine\base.py", line 1848, in _execute_context
return self._exec_single_context(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\sqlalchemy\engine\base.py", line 1988, in _exec_single_context
self._handle_dbapi_exception(
File "C:\Python311\Lib\site-packages\sqlalchemy\engine\base.py", line 2344, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "C:\Python311\Lib\site-packages\sqlalchemy\engine\base.py", line 1969, in _exec_single_context
self.dialect.do_execute(
File "C:\Python311\Lib\site-packages\sqlalchemy\engine\default.py", line 922, in do_execute
cursor.execute(statement, parameters)
File "C:\Python311\Lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 580, in execute
self.adapt_connection.await(
File "C:\Python311\Lib\site-packages\sqlalchemy\util_concurrency_py3k.py", line 130, in await_only
return current.driver.switch(awaitable) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\sqlalchemy\util_concurrency_py3k.py", line 195, in greenlet_spawn
value = await result
^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 558, in _prepare_and_execute
self._handle_exception(error)
File "C:\Python311\Lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 509, in _handle_exception
self._adapt_connection._handle_exception(error)
File "C:\Python311\Lib\site-packages\sqlalchemy\dialects\postgresql\asyncpg.py", line 797, in _handle_exception
raise translated_error from error
sqlalchemy.exc.ProgrammingError: (sqlalchemy.dialects.postgresql.asyncpg.ProgrammingError) <class 'asyncpg.exceptions.UndefinedObjectError'>: role "None" does not exist
[SQL: GRANT ALL ON SCHEMA case_graph TO "None";]
(Background on this error at: https://sqlalche.me/e/20/f405)

ERROR: error executing step command 'provision': failed running post hooks: 'postprovision' hook failed with exit code: '1', Path: 'C:\Users\AANTON~1\AppData\Local\Temp\azd-postprovision-2881539855.ps1'. : exit code: 1

any idea on how to solve ?

thanks in advance,

Alex

@mazer-rakham
Copy link

mazer-rakham commented Dec 19, 2024

I modified setup_postres_azurerole.py to the following and it fixed that error:
`import argparse
import asyncio
import logging
import os
import sys

current_dir = os.path.abspath(os.path.dirname(file))
backend_dir = os.path.abspath(os.path.join(current_dir, ".."))
sys.path.append(backend_dir)

print("Current sys.path:", sys.path)
print("Contents of backend_dir:", os.listdir(backend_dir))

from dotenv import load_dotenv
from sqlalchemy import text
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession
from fastapi_app.postgres_engine import create_postgres_engine_from_args, create_postgres_engine_from_env

logger = logging.getLogger("legalcaseapp")

async def create_ag_catalog_schema(engine):
async with engine.begin() as conn:
logger.info("Ensuring 'ag_catalog' schema exists...")
create_schema_sql = """
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_namespace WHERE nspname = 'ag_catalog') THEN
EXECUTE 'CREATE SCHEMA ag_catalog';
END IF;
END
$$;
"""
await conn.execute(text(create_schema_sql))

async def assign_role_for_webapp(engine, app_identity_name):
async with engine.begin() as conn:
await create_ag_catalog_schema(engine)
logger.info(f"Creating PostgreSQL role for identity {app_identity_name}")
await conn.execute(text(f"SELECT * FROM pgaadauth_create_principal('{app_identity_name}', false, false)"))
logger.info(f"Granting permissions to {app_identity_name}")
await conn.execute(text(f'GRANT USAGE ON SCHEMA ag_catalog TO "{app_identity_name}"'))

async def main():
parser = argparse.ArgumentParser(description="Setup database for legal cases.")
parser.add_argument("--host", required=True, help="Host for PostgreSQL")
parser.add_argument("--username", required=True, help="Username for PostgreSQL")
parser.add_argument("--database", required=True, help="Database name for PostgreSQL")
parser.add_argument("--app_identity_name", required=True, help="App Identity Name for PostgreSQL role")
args = parser.parse_args()
engine = create_postgres_engine_from_args(args.host, args.username, args.database)
await assign_role_for_webapp(engine, args.app_identity_name)

if name == "main":
logging.basicConfig(level=logging.INFO)
logger.setLevel(logging.INFO)
load_dotenv(override=True)
asyncio.run(main())`

@mazer-rakham
Copy link

I created a fork here that deploys successfully, you might have to modify the py scripts to use "python" on your machine, my machine uses "py"

https://github.com/mazer-rakham/graphrag-legalcases-postgres/tree/thomas-flock-suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants