Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
samscott89 committed Jun 11, 2024
1 parent 7031fc0 commit 15fe137
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions languages/python/sqlalchemy-oso/sqlalchemy_oso/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Keep us compatible with multiple SQLAlchemy versions by implementing wrappers
when needed here.
"""

import sqlalchemy
from packaging.version import parse

Expand Down
1 change: 1 addition & 0 deletions languages/python/sqlalchemy-oso/sqlalchemy_oso/session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""SQLAlchemy session classes and factories for oso."""

import logging
from typing import Any, Callable, Dict, Optional, Type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
We must detect all entities properly to apply authorization.
"""

import sqlalchemy
from sqlalchemy import inspect
from sqlalchemy.orm.util import AliasedClass, AliasedInsp
Expand All @@ -20,10 +21,12 @@ def to_class(entity):
else:
return entity


if USING_SQLAlchemy_v1_3:
# unsupported for <= 1.3
def all_entities_in_statement(statement):
raise NotImplementedError("Unsupported on SQLAlchemy < 1.4")

else:
if USING_SQLAlchemy_v2_0:

Expand Down Expand Up @@ -78,6 +81,7 @@ def get_joinedload_entities(stmt):
entities.add(loadopt.path[-1].entity)

return entities

else:
# Start POC code from @zzzeek (Mike Bayer)
# TODO: Still needs to be generalized & support other options.
Expand Down Expand Up @@ -123,7 +127,10 @@ def get_joinedload_entities(stmt):
elif hasattr(opt, "context"):
# these options are called Load
for key, loadopt in opt.context.items():
if key[0] == "loader" and ("lazy", "joined") in loadopt.strategy:
if (
key[0] == "loader"
and ("lazy", "joined") in loadopt.strategy
):
# the "path" is a tuple showing the entity/relationships
# being targeted

Expand Down Expand Up @@ -218,4 +225,3 @@ class A(Base):
default_entities.add(rel.mapper)

return default_entities

1 change: 1 addition & 0 deletions languages/python/sqlalchemy-oso/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from sqlalchemy import Boolean, Column, Enum, ForeignKey, Integer, String
from sqlalchemy.orm import relationship

if USING_SQLAlchemy_v1_3:
from sqlalchemy.ext.declarative import declarative_base
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def test_get_joinedload_entities(stmt, o):
assert set(map(to_class, get_joinedload_entities(stmt))) == o



def test_default_loader_strategies_all_entities_in_statement():
"""Test that all_entitites_in_statement finds default "joined" entities."""
Base2 = declarative_base()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Tests come from the relationship document & operations laid out there
https://www.notion.so/osohq/Relationships-621b884edbc6423f93d29e6066e58d16.
"""

import pytest

from sqlalchemy_oso.auth import authorize_model
Expand Down Expand Up @@ -183,7 +184,7 @@ def tag_test_fixture(session):

# HACK!
objects = {}
for (name, local) in locals().items():
for name, local in locals().items():
if name != "session" and name != "objects":
session.add(local)

Expand Down Expand Up @@ -259,7 +260,7 @@ def tag_nested_test_fixture(session):

# HACK!
objects = {}
for (name, local) in locals().items():
for name, local in locals().items():
if name != "session" and name != "objects":
session.add(local)

Expand Down Expand Up @@ -357,7 +358,7 @@ def tag_nested_many_many_test_fixture(session):

# HACK!
objects = {}
for (name, local) in locals().items():
for name, local in locals().items():
if name != "session" and name != "objects":
session.add(local)

Expand Down
1 change: 1 addition & 0 deletions languages/python/sqlalchemy-oso/tests/test_sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test hooks & SQLAlchemy API integrations."""

import pytest
from sqlalchemy.orm import aliased, joinedload

Expand Down

0 comments on commit 15fe137

Please sign in to comment.