title: Having a trouble while application deployment- "sqlalchemy.exc.InvalidRequestError:"
body: <p>sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'mapped class Alert-&gt;alerts'. Original exception was: When initializing mapper mapped class Alert-&gt;alerts, expression 'Slice' failed to locate a name ('Slice'). If this is a class name, consider adding this relationship() to the &lt;class 'superset.models.alerts.Alert'&gt; class after both dependent classes have been defined. How to resolve this issue?</p>
  <pre><code>127.0.0.1 - - [30/Aug/2021 07:12:15] &quot;GET /health HTTP/1.1&quot; 500 -
  INFO:werkzeug:127.0.0.1 - - [30/Aug/2021 07:12:15] &quot;GET /health HTTP/1.1&quot; 500 -
  INFO:root:Configured event logger of type &lt;class 'superset.utils.log.DBEventLogger'&gt;
  INFO:superset.utils.logging_configurator:logging was configured successfully
  ERROR:superset.app:Failed to create app
  Traceback (most recent call last):
    File &quot;/app/superset/app.py&quot;, line 62, in create_app
      app_initializer.init_app()
    File &quot;/app/superset/app.py&quot;, line 552, in init_app
      self.init_app_in_ctx()
    File &quot;/app/superset/app.py&quot;, line 521, in init_app_in_ctx
      self.configure_fab()
    File &quot;/app/superset/app.py&quot;, line 592, in configure_fab
      appbuilder.init_app(self.flask_app, db.session)
    File &quot;/usr/local/lib/python3.7/site-packages/flask_appbuilder/base.py&quot;, line 202, in init_app
      self.sm = self.security_manager_class(self)
    File &quot;/app/superset/custom_apis/base/custom_main.py&quot;, line 29, in __init__
      super(CustomSecurityManager, self).__init__(appbuilder)
    File &quot;/usr/local/lib/python3.7/site-packages/flask_appbuilder/security/sqla/manager.py&quot;, line 55, in __init__
      user_datamodel = SQLAInterface(self.user_model)
    File &quot;/usr/local/lib/python3.7/site-packages/flask_appbuilder/models/sqla/interface.py&quot;, line 62, in __init__
      for prop in sa.orm.class_mapper(obj).iterate_properties:
    File &quot;/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/base.py&quot;, line 451, in class_mapper
      mapper = _inspect_mapped_class(class_, configure=configure)
    File &quot;/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/base.py&quot;, line 430, in _inspect_mapped_class
      mapper._configure_all()
    File &quot;/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/mapper.py&quot;, line 1352, in _configure_all
      configure_mappers()
    File &quot;/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/mapper.py&quot;, line 3295, in configure_mappers
      raise e
  sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'mapped class Alert-&gt;alerts'. Original exception was: When initializing mapper mapped class Alert-&gt;alerts, expression 'Slice' failed to locate a name ('Slice'). If this is a class name, consider adding this relationship() to the &lt;class 'superset.models.alerts.Alert'&gt; class after both dependent classes have been defined.
  </code></pre>
  <p>Alert-Model code structure:</p>
  <pre><code>class Alert(Model, AuditMixinNullable):
  
      &quot;&quot;&quot;Schedules for emailing slices / dashboards&quot;&quot;&quot;
  
      __tablename__ = &quot;alerts&quot;
  
      id = Column(Integer, primary_key=True)
      label = Column(String(150), nullable=False)
      active = Column(Boolean, default=True, index=True)
      # TODO(bkyryliuk): enforce minimal supported frequency
      crontab = Column(String(50), nullable=False)
  
      alert_type = Column(String(50))
      owners = relationship(security_manager.user_model, secondary=alert_owner)
      recipients = Column(Text)
      slack_channel = Column(Text)
  
      # TODO(bkyryliuk): implement log_retention
      log_retention = Column(Integer, default=90)
      grace_period = Column(Integer, default=60 * 60 * 24)
  
      slice_id = Column(Integer, ForeignKey(&quot;slices.id&quot;))
      slice = relationship(&quot;Slice&quot;, backref=&quot;alerts&quot;, foreign_keys=[slice_id])
  
      dashboard_id = Column(Integer, ForeignKey(&quot;dashboards.id&quot;))
      dashboard = relationship(&quot;Dashboard&quot;, backref=&quot;alert&quot;, foreign_keys=[dashboard_id])
  
      last_eval_dttm = Column(DateTime, default=datetime.utcnow)
      last_state = Column(String(10))
  
      # Observation related columns
      sql = Column(Text, nullable=False)
  </code></pre>
  <p>Slice model :</p>
  <pre><code>class Slice(
      Model, AuditMixinNullable, ImportExportMixin
  ):  # pylint: disable=too-many-public-methods
  
      &quot;&quot;&quot;A slice is essentially a report or a view on data&quot;&quot;&quot;
  
      __tablename__ = &quot;slices&quot;
      id = Column(Integer, primary_key=True)
      slice_name = Column(String(250))
      datasource_id = Column(Integer)
      datasource_type = Column(String(200))
      datasource_name = Column(String(2000))
      viz_type = Column(String(250))
      params = Column(Text)
      description = Column(Text)
      cache_timeout = Column(Integer)
      perm = Column(String(1000))
      schema_perm = Column(String(1000))
      owners = relationship(security_manager.user_model, secondary=slice_user)
      table = relationship(
          &quot;SqlaTable&quot;,
          foreign_keys=[datasource_id],
          primaryjoin=&quot;and_(Slice.datasource_id == SqlaTable.id, &quot;
          &quot;Slice.datasource_type == 'table')&quot;,
          remote_side=&quot;SqlaTable.id&quot;,
          lazy=&quot;subquery&quot;,
      )
  
      token = &quot;&quot;
  
      export_fields = [
          &quot;slice_name&quot;,
          &quot;datasource_type&quot;,
          &quot;datasource_name&quot;,
          &quot;viz_type&quot;,
          &quot;params&quot;,
          &quot;cache_timeout&quot;,
      ]
      export_parent = &quot;table&quot;
  </code></pre>
  <p><strong>SUPERSET-VERSION:</strong> 0.38.0</p>