Skip to content

Commit

Permalink
modify add user to accept gets
Browse files Browse the repository at this point in the history
  • Loading branch information
madeofpendletonwool committed Dec 22, 2024
1 parent 2ae4173 commit 6695890
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions database_functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ def add_person_podcast(cnx, database_type, podcast_values, user_id, username=Non
def add_user(cnx, database_type, user_values):
cursor = cnx.cursor()
try:
print(f"Adding user with values: {user_values}")
if database_type == "postgresql":
add_user_query = """
INSERT INTO "Users"
Expand All @@ -469,18 +470,19 @@ def add_user(cnx, database_type, user_values):
if result is None:
raise Exception("Failed to create user - no ID returned")

# Handle both tuple and dict return types
user_id = result[0] if isinstance(result, tuple) else result.get('userid', result[0])
# Print the result for debugging
print(f"Raw PostgreSQL result: {result}")
logging.debug(f"Raw PostgreSQL result: {result}")

if not user_id:
raise Exception("Failed to create user - invalid ID returned")
# Handle different return types
if isinstance(result, dict):
# Try different case variations
user_id = result.get('userid') or result.get('UserID') or result.get('userId') or result.get('user_id')
else:
user_id = result[0]

logging.debug(f"PostgreSQL insert result: {result}, extracted user_id: {user_id}")
else:
user_id = cursor.lastrowid
if not user_id:
raise Exception("Failed to create user - no ID returned")

raise Exception("Failed to create user - invalid ID returned")
# Add user settings
settings_query = """
INSERT INTO "UserSettings"
Expand Down

0 comments on commit 6695890

Please sign in to comment.