Skip to content

Commit

Permalink
Refactor User model rebuild to troubleshoot test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Nov 23, 2024
1 parent a6eb73a commit b060c95
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
2 changes: 2 additions & 0 deletions neon_data_models/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from neon_data_models.models.user import *
User.rebuild_model()

from neon_data_models.models.client import *
from neon_data_models.models.api import *
18 changes: 0 additions & 18 deletions neon_data_models/models/api/mq/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@


class CreateUserRequest(MQContext):
def __init__(self, **kwargs):
# `User` may be rebuilt upon init, so make sure this model is too
User.model_rebuild()
self.model_rebuild()
MQContext.__init__(self, **kwargs)

operation: Literal["create"] = "create"
user: User = Field(description="User object to create")

Expand Down Expand Up @@ -66,12 +60,6 @@ def validate_params(self) -> 'ReadUserRequest':


class UpdateUserRequest(MQContext):
def __init__(self, **kwargs):
# `User` may be rebuilt upon init, so make sure this model is too
User.model_rebuild()
self.model_rebuild()
MQContext.__init__(self, **kwargs)

operation: Literal["update"] = "update"
user: User = Field(description="Updated User object to write to database")
auth_username: str = Field(
Expand All @@ -97,12 +85,6 @@ def get_auth_username(self) -> 'UpdateUserRequest':


class DeleteUserRequest(MQContext):
def __init__(self, **kwargs):
# `User` may be rebuilt upon init, so make sure this model is too
User.model_rebuild()
self.model_rebuild()
MQContext.__init__(self, **kwargs)

operation: Literal["delete"] = "delete"
user: User = Field(description="Exact User object to remove from the "
"database")
Expand Down
7 changes: 4 additions & 3 deletions neon_data_models/models/user/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ class TokenConfig(BaseModel):


class User(BaseModel):
def __init__(self, **kwargs):

@classmethod
def rebuild_model(cls):
# Ensure `HanaToken` is populated from the import space
from neon_data_models.models.api.jwt import HanaToken
self.model_rebuild()
BaseModel.__init__(self, **kwargs)
cls.model_rebuild()

username: str
password_hash: Optional[str] = None
Expand Down

0 comments on commit b060c95

Please sign in to comment.