Skip to content

Using docs/logic can duplicate logic #83

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

Open
valhuber opened this issue Feb 21, 2025 · 0 comments
Open

Using docs/logic can duplicate logic #83

valhuber opened this issue Feb 21, 2025 · 0 comments
Assignees

Comments

@valhuber
Copy link
Contributor

Multiple logic files (as described in the docs/logic/readme.md) can result in duplicated logic in logic/logic_discovery, e.g.:

import datetime
from decimal import Decimal
from logic_bank.exec_row_logic.logic_row import LogicRow
from logic_bank.extensions.rule_extensions import RuleExtension
from logic_bank.logic_bank import Rule
import database.models as models
import api.system.opt_locking.opt_locking as opt_locking
from security.system.authorization import Grant, Security
import logging

logger = logging.getLogger(__name__)

def declare_logic():
    ''' Declarative multi-table derivations and constraints, extensible with Python.
 
    Brief background: see readme_declare_logic.md
    
    Your Code Goes Here - Use code completion (Rule.) to declare rules
    '''

    # this logic is automatically discovered by declare_logic.py#discover_logic()

    # Logic from GenAI: (or, use your IDE w/ code completion)
    from database.models import Product, Customer

    # Ensure customer names are not 'x'.
    Rule.constraint(validate=Customer, 
                as_condition=lambda row: row.name.lower() != 'x', 
                error_msg="Customer name cannot be 'x'")

    # Ensure credit limits are non-negative.
    Rule.constraint(validate=Customer, 
                as_condition=lambda row: row.credit_limit >= 0, 
                error_msg="Credit limit cannot be negative")

    # Ensure product names are not 'x'.
    Rule.constraint(validate=Product, 
                as_condition=lambda row: row.name.lower() != 'x', 
                error_msg="Product name cannot be 'x'")

    # Ensure product prices are positive.
    Rule.constraint(validate=Product, 
                as_condition=lambda row: row.unit_price > 0, 
                error_msg="Product price must be positive")

    # End Logic from GenAI

    
    # Logic from GenAI February 21, 2025 09:33:23:
@valhuber valhuber self-assigned this Feb 21, 2025
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

1 participant