Changeset - 1641e0ea14d6
[Not reviewed]
0 20 0
Lance Edgar (lance) - 2 months ago 2024-09-03 10:57:59
lance@edbob.org
fix: add startup workaround for trainwreck query bug

not at all clear why, but c621e21cd4b4a2a408d8a32ace0b34afe6fdf526 has
introduced some strange bug where the "first" trainwreck query will
raise an error and yet subsequent queries work fine.

so now in the startup sequence we simply force a query, which for
unknown reasons does *not* raise any error, and will somehow magically
prevent the error when a "normal" trainwreck query happens later.

AFAIK this is a "benign" operation and causes no real side effects
other than preventing the strange error. fingers crossed, this is
fine and will not cause further problems...??!
20 files changed with 61 insertions and 101 deletions:
0 comments (0 inline, 0 general)
rattail/config.py
Show inline comments
 
@@ -785,6 +785,23 @@ def make_config(
 
        if Session:
 
            Session.configure(future=True)
 

	
 
    # TODO: holy crap why is this needed?  without it, the first time
 
    # a trainwreck query happens, InvalidRequestError is raised.  but
 
    # this is clearly a trainwreck query, and yet no error if we do it
 
    # this early in the startup sequence?!  i have no idea what is
 
    # going on here but at least this "works" - fingers crossed..
 
    if getattr(config, 'trainwreck_engines', None):
 
        app = config.get_app()
 
        trainwreck = app.get_trainwreck_handler()
 
        try:
 
            trainwreck_model = trainwreck.get_model()
 
        except WuttaConfigurationError:
 
            pass
 
        else:
 
            trainwreck_session = trainwreck.make_session()
 
            trainwreck_session.query(trainwreck_model.Transaction).first()
 
            trainwreck_session.close()
 

	
 
    return config
 

	
 

	
tests/autocomplete/test_base.py
Show inline comments
 
@@ -4,7 +4,7 @@ from unittest import TestCase
 

	
 
import pytest
 

	
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 
from rattail.autocomplete import base as mod
 
from rattail.db import Session
 

	
 
@@ -12,12 +12,9 @@ from rattail.db import Session
 
class TestAutocompleter(TestCase):
 

	
 
    def setUp(self):
 
        self.config = self.make_config()
 
        self.config = RattailConfig()
 
        self.app = self.config.get_app()
 

	
 
    def make_config(self):
 
        return make_config([], extend=False)
 

	
 
    def test_constructor(self):
 

	
 
        # cannot instantiate autocompleter with no key
 
@@ -132,12 +129,9 @@ class TestAutocompleter(TestCase):
 
class TestPhoneMagicMixin(TestCase):
 

	
 
    def setUp(self):
 
        self.config = self.make_config()
 
        self.config = RattailConfig()
 
        self.app = self.config.get_app()
 

	
 
    def make_config(self):
 
        return make_config([], extend=False)
 

	
 
    def test_autocomplete(self):
 
        try:
 
            import sqlalchemy as sa
tests/autocomplete/test_brands.py
Show inline comments
 
@@ -2,7 +2,7 @@
 

	
 
from unittest import TestCase
 

	
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 
try:
 
    import sqlalchemy as sa
 
@@ -15,13 +15,10 @@ else:
 
    class TestBrandAutocompleter(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.autocompleter = self.make_autocompleter()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 
        def make_autocompleter(self):
 
            return mod.BrandAutocompleter(self.config)
 

	
tests/autocomplete/test_customers.py
Show inline comments
 
@@ -2,7 +2,7 @@
 

	
 
from unittest import TestCase
 

	
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 
try:
 
    import sqlalchemy as sa
 
@@ -15,13 +15,10 @@ else:
 
    class TestCustomerAutocompleter(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.autocompleter = self.make_autocompleter()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 
        def make_autocompleter(self):
 
            return mod.CustomerAutocompleter(self.config)
 

	
tests/autocomplete/test_departments.py
Show inline comments
 
@@ -2,7 +2,7 @@
 

	
 
from unittest import TestCase
 

	
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 
try:
 
    import sqlalchemy as sa
 
@@ -15,13 +15,10 @@ else:
 
    class TestDepartmentAutocompleter(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.autocompleter = self.make_autocompleter()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 
        def make_autocompleter(self):
 
            return mod.DepartmentAutocompleter(self.config)
 

	
tests/autocomplete/test_employees.py
Show inline comments
 
@@ -3,7 +3,7 @@
 
from unittest import TestCase
 

	
 

	
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 
try:
 
    import sqlalchemy as sa
 
@@ -16,13 +16,10 @@ else:
 
    class TestEmployeeAutocompleter(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.autocompleter = self.make_autocompleter()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 
        def make_autocompleter(self):
 
            return mod.EmployeeAutocompleter(self.config)
 

	
tests/autocomplete/test_people.py
Show inline comments
 
@@ -2,7 +2,7 @@
 

	
 
from unittest import TestCase
 

	
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 
try:
 
    import sqlalchemy as sa
 
@@ -15,13 +15,10 @@ else:
 
    class TestPersonAutocompleter(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.autocompleter = self.make_autocompleter()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 
        def make_autocompleter(self):
 
            return mod.PersonAutocompleter(self.config)
 

	
 
@@ -59,13 +56,10 @@ else:
 
    class TestPersonEmployeeAutocompleter(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.autocompleter = self.make_autocompleter()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 
        def make_autocompleter(self):
 
            return mod.PersonEmployeeAutocompleter(self.config)
 

	
tests/autocomplete/test_products.py
Show inline comments
 
@@ -2,7 +2,7 @@
 

	
 
from unittest import TestCase
 

	
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 
try:
 
    import sqlalchemy as sa
 
@@ -15,7 +15,7 @@ else:
 
    class AutocompleterTestCase(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.autocompleter = self.make_autocompleter()
 

	
 
@@ -28,9 +28,6 @@ else:
 
            self.session.rollback()
 
            self.session.close()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 

	
 
    class TestProductAutocompleter(AutocompleterTestCase):
 

	
tests/autocomplete/test_vendors.py
Show inline comments
 
@@ -2,7 +2,7 @@
 

	
 
from unittest import TestCase
 

	
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 
try:
 
    import sqlalchemy as sa
 
@@ -15,13 +15,10 @@ else:
 
    class TestVendorAutocompleter(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.autocompleter = self.make_autocompleter()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 
        def make_autocompleter(self):
 
            return mod.VendorAutocompleter(self.config)
 

	
tests/batch/test_handheld.py
Show inline comments
 
@@ -2,7 +2,7 @@
 

	
 
from unittest import TestCase
 

	
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 
try:
 
    import sqlalchemy as sa
 
@@ -15,13 +15,10 @@ else:
 
    class TestHandheldBatchHandler(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.handler = self.make_handler()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 
        def make_handler(self):
 
            return mod.HandheldBatchHandler(self.config)
 

	
tests/batch/test_handlers.py
Show inline comments
 
@@ -4,7 +4,7 @@ import os
 
from unittest import TestCase
 

	
 
from rattail.batch import handlers as mod
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 
from rattail.db import Session
 

	
 
try:
 
@@ -16,13 +16,10 @@ else:
 
    class TestBatchHandler(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.handler = self.make_handler()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 
        def make_handler(self):
 
            return mod.BatchHandler(self.config)
 

	
tests/batch/test_product.py
Show inline comments
 
@@ -2,7 +2,7 @@
 

	
 
from unittest import TestCase
 

	
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 
try:
 
    import sqlalchemy as sa
 
@@ -15,13 +15,10 @@ else:
 
    class TestProductBatchHandler(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.handler = self.make_handler()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 
        def make_handler(self):
 
            return mod.ProductBatchHandler(self.config)
 

	
tests/batch/test_vendorcatalog.py
Show inline comments
 
@@ -5,7 +5,7 @@ import shutil
 
import decimal
 
from unittest import TestCase
 

	
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 
from rattail.excel import ExcelWriter
 
from rattail.gpc import GPC
 

	
 
@@ -20,13 +20,10 @@ else:
 
    class TestProductBatchHandler(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.handler = self.make_handler()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 
        def make_handler(self):
 
            return mod.VendorCatalogHandler(self.config)
 

	
tests/test_app.py
Show inline comments
 
@@ -11,7 +11,7 @@ import pytest
 
from wuttjamaican.exc import ConfigurationError
 

	
 
from rattail import app as mod
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 
from rattail.core import Object
 
from rattail.db import Session
 
from rattail.autocomplete import Autocompleter
 
@@ -33,7 +33,7 @@ else:
 
class TestAppHandler(TestCase):
 

	
 
    def setUp(self):
 
        self.config = make_config([], extend=False)
 
        self.config = RattailConfig()
 
        self.app = mod.AppHandler(self.config)
 
        self.config.app = self.app
 

	
tests/test_auth.py
Show inline comments
 
@@ -2,7 +2,7 @@
 

	
 
from unittest import TestCase
 

	
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 
try:
 
    import sqlalchemy as sa
 
@@ -15,13 +15,10 @@ else:
 
    class TestAuthHandler(TestCase):
 

	
 
        def setUp(self):
 
            self.config = self.make_config()
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.handler = self.make_handler()
 

	
 
        def make_config(self):
 
            return make_config([], extend=False)
 

	
 
        def make_handler(self):
 
            return mod.AuthHandler(self.config)
 

	
tests/test_clientele.py
Show inline comments
 
@@ -3,7 +3,7 @@
 
from unittest import TestCase
 

	
 
from rattail import clientele
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 
try:
 
    import sqlalchemy as sa
 
@@ -14,7 +14,7 @@ else:
 
    class TestClienteleHandler(TestCase):
 

	
 
        def setUp(self):
 
            self.config = make_config([], extend=False)
 
            self.config = RattailConfig()
 
            self.app = self.config.get_app()
 
            self.handler = clientele.ClienteleHandler(self.config)
 
            self.engine = sa.create_engine('sqlite://')
tests/test_excel.py
Show inline comments
 
@@ -8,16 +8,13 @@ from unittest import TestCase
 
import openpyxl
 

	
 
from rattail import excel as mod
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 

	
 
class TestExcelReaderXLSX(TestCase):
 

	
 
    def setUp(self):
 
        self.config = self.make_config()
 

	
 
    def make_config(self):
 
        return make_config([], extend=False)
 
        self.config = RattailConfig()
 

	
 
    def test_strip_fieldnames(self):
 
        app = self.config.get_app()
tests/test_labels.py
Show inline comments
 
@@ -7,19 +7,16 @@ import shutil
 
from unittest import TestCase
 

	
 
from rattail import labels as mod
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 
from rattail.exceptions import LabelPrintingError
 

	
 

	
 
class TestLabelPrinter(TestCase):
 

	
 
    def setUp(self):
 
        self.config = self.make_config()
 
        self.config = RattailConfig()
 
        self.printer = self.make_printer()
 

	
 
    def make_config(self):
 
        return make_config([], extend=False)
 

	
 
    def make_printer(self):
 
        return mod.LabelPrinter(self.config)
 

	
 
@@ -33,14 +30,11 @@ class TestLabelPrinter(TestCase):
 
class TestCommandFilePrinter(TestCase):
 

	
 
    def setUp(self):
 
        self.config = self.make_config()
 
        self.config = RattailConfig(defaults={
 
            'rattail.timezone.default': 'America/Chicago',
 
        })
 
        self.printer = self.make_printer()
 

	
 
    def make_config(self):
 
        config = make_config([], extend=False)
 
        config.setdefault('rattail', 'timezone.default', 'America/Chicago')
 
        return config
 

	
 
    def make_printer(self):
 
        printer = mod.CommandFilePrinter(self.config)
 
        printer.formatter = mod.CommandFormatter(self.config, template="")
tests/test_products.py
Show inline comments
 
@@ -5,7 +5,7 @@ from unittest import TestCase
 
import pytest
 

	
 
from rattail import products as mod
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 
from rattail.gpc import GPC
 
from rattail.db import Session
 

	
 
@@ -13,13 +13,10 @@ from rattail.db import Session
 
class TestProductsHandler(TestCase):
 

	
 
    def setUp(self):
 
        self.config = self.make_config()
 
        self.config = RattailConfig()
 
        self.app = self.config.get_app()
 
        self.handler = self.make_handler()
 

	
 
    def make_config(self):
 
        return make_config([], extend=False)
 

	
 
    def make_handler(self):
 
        return mod.ProductsHandler(self.config)
 

	
tests/test_time.py
Show inline comments
 
@@ -7,13 +7,13 @@ import pytz
 
from wuttjamaican.exc import ConfigurationError
 

	
 
from rattail import time
 
from rattail.config import make_config
 
from rattail.config import RattailConfig
 

	
 

	
 
class TestLocaltime(TestCase):
 

	
 
    def setUp(self):
 
        self.config = make_config([], extend=False)
 
        self.config = RattailConfig()
 
        self.config.setdefault('rattail', 'timezone.default', 'America/Los_Angeles')
 
        self.config.setdefault('rattail', 'timezone.missouri', 'America/Chicago')
 

	
 
@@ -52,7 +52,7 @@ class TestLocaltime(TestCase):
 
class TestTimezone(TestCase):
 

	
 
    def setUp(self):
 
        self.config = make_config([], extend=False)
 
        self.config = RattailConfig()
 

	
 
    def test_default_timezone_returned_by_default(self):
 
        self.config.setdefault('rattail', 'timezone.default', 'Antarctica/Rothera')
0 comments (0 inline, 0 general)