Skip to content
Snippets Groups Projects
This project is mirrored from https://github.com/metabase/metabase. Pull mirroring updated .
  1. Feb 01, 2022
  2. Jan 31, 2022
    • Noah Moss's avatar
      f36b9efa
    • Howon Lee's avatar
      Static viz funnel fix (more #18676) (#19983) · d31fac77
      Howon Lee authored
      Still pursuant to #18676
      
      1. Funnel was previously not doing lato font for the bold bit because visx's text doesn't take weights, it takes styles
      2. Columns can be nontrivial with respect to funnels, which was an oversight
      3. For some reason the first try for fixing 2 also impinged upon values being strings for funnels, which breaks things at SVG level
      4. And let's just shove in a nit for the display of trends if the previous value and current value are the same
      d31fac77
    • Howon Lee's avatar
      Card copy trs fix (#20063) · 385fa88f
      Howon Lee authored
      
      CI was broken inasmuch as it wasn't running, so master was broken without us knowing it. Thankfully, to the best of our knowledge, it was a couple of nits. Fixes master.
      
      Co-authored-by: default avatarAleksandr Lesnenko <alxnddr@gmail.com>
      385fa88f
    • Jeff Evans's avatar
      Fix NullPointerException in Postgres when using client SSL properties (#20034) · a2f4563c
      Jeff Evans authored
      Only attempt to read values that were actually set on the client side
      
      Add test to confirm specific combination from reported issue works
      a2f4563c
    • dpsutton's avatar
      Metadata lifecycle improvements master (#19899) · 1b9270fd
      dpsutton authored
      * Improve lifecycle of metadata
      
      Previously we have assumed that if valid metadata is passed into the
      card create and udpate, that that is valid metadata for the query. There
      are a few scenarios where this can fail, but they all boil down to
      editing the query after running it. Examples:
      
      - when creating a query, come up with a query, visualize, realize you
      wanted to not select all columns, edit to not select those, possibly
      select a few extra, and then save. The saved metadata might only have
      the columns from when you ran the query and not after you saved it.
      - edit an existing query and save without rerunning. Again, adding and
      removing some columns.
      
      How it affects:
      - if you remove columns, the preserved metadata can cause us to attempt
      to select columns that are no longer in that question, leading to errors
      for nested queries
      - if you add columns, the query builder won't show the new columns until
      that information is populated in the metadata by running the query.
      
      Lifecycle now:
      - should be encapsulated in `api.card/result-metadata-async`. But we
      only allow metadata to remain if is is valid metadata and the query has
      not been edited. If the query has been edited (and new queries always
      satisfy this since the previous query will be nil) we rerun the query to
      get the metadata. No more drift. However, when dealing with datasets we
      will attempt to blend the existing metadata into the newly computed
      metadata so that metadata edits can persevere.
      
      Other changes:
      
      - removed an extra indirection in the card api that made it harder to
      reason about when to recompute metadata
      - moved the `combine-metadata` function into a util namespace and gave
      some more generic parameter names
      - deleted two tests that are no longer relevant after removing the
      checksum on metadata. One had to do with how we hash floats vs ints
      which is no longer relevant since we aren't hashing at all (RIP
      checksum) and one checked that we accepted "valid" checksum-ed
      metadata.
      - new test that updating a card will update its metadata by rerunning
      the query
      - when validating the checksum, do not call s/validate since this WILL
      THROW. Instead check `(nil? (s/check ...))`.
      
      * Normalize query before comparing for changes
      
      When comparing db vs api-sent query, need to normalize otherwise they
      will always be different and our optimization will never kick in
      
      * Fix ns
      
      * Cleanup after ourselves
      
      * Move `combine-metadata` util functions to a better namespace
      
      * Allow for no query in api/card/:id patch
      
      Cypress tests would do a
      
      ```javascript
        describe("simple mode", () => {
          beforeEach(() => {
            cy.request("PUT", "/api/card/1", {
              name: "Orders Model",
              dataset: true,
            });
          });
      ```
      
      The metadata testing stuff would always use the query from the PUT to
      check whether to dump or retain the metadata. In these instances, it
      would dump the metadata and then i guess ask the qp for the metadata for
      a nil query. Similar scenario if anyone uses the API to update
      descriptions, etc.
      
      The method is PUT not PATCH, but in the saving function we have
      
      ```clojure
      (u/select-keys-when
       card-updates
       :present #{:collection_id :collection_position :description :cache_ttl :dataset}
       :non-nil #{:dataset_query :display :name :visualization_settings
                  :archived :enable_embedding :embedding_params
                  :result_metadata})
      ```
      
      So we kinda have a PATCH anyways.
      
      * Normalize metadata before blending
      
      * Ensure api blends metadata correctly
      
      When blending the metadata, need to update the field_ref to keyword the
      original. Otherwise we are attempting to match up the field with ref
      ["field" "subtotal"] against [:field "subtotal"] and they don't match.
      
      * Normalize metadata from api correctly
      
      if you just call normalize/normalize it doesn't know not to change
      `:field_ref` -> `:field-ref` so it gets out of whack. Need to pass it
      the function appropriate for that level.
      
      Also add a test that you can update _just_ the metadata. This actually
      already worked for a subtle reason, and that is possibly buggy. The
      reasoning is that the result_metadata is clobbered conditionally now
      instead of unconditionally. If the async metadata stuff returns nil it
      won't clobber and then whatever was sent over the wire goes in.
      
      * Ensure previous metadata is there
      
      When updating the query of a dataset, handle the case where just the
      query is sent, and not the whole card. If the client didn't send the
      previous metadata, we did not look it up in the database
      
      * Card api always uses metadata from `result-metadata-async`
      
      Originally this did
      
          (assoc card-data :result_metadata (a/<! result-metadata-chan))
      
      But I changed that so it only optionally did so when that channel had
      information. The problem with this is that if there was :result_metadata
      on the original request but the channel returned nil for some reason,
      whatever was in the request was going in the db. This includes invalid
      metadata, non-json strings, what ever. Obviously bad.
      
      But we need to handle PATCHs where clients don't send metadata or they
      _ONLY_ send metadata and no query, etc. So this always uses the results
      of `result-metadata-async` so it can go through that logic and we always
      clobber.
      
      And remember that if we only update the result_metadata when it is
      non-nil (`update-card-async!`). The end result is that switching from a
      PATCH model where you expect the full object to a PUT where things can
      be optional has lots of footguns. Some examples:
      - only updating the query
      - updating the query along with edits to the metadata on a card (throw
      the metadata away)
      - updating the query along with edits on a dataset (save the metadata
      but blend it into the fresh computation of the query's metadata)
      - updating the query but not sending along the metadata. Need to grab
      from the db and blend in.
      - Sending invalid metadata, changing the description. We want to toss
      away the metadata but save the description.
      1b9270fd
  3. Jan 28, 2022
  4. Jan 27, 2022
    • Bryan Maass's avatar
      Check user exists for setup redirect (#19846) · 0526d88f
      Bryan Maass authored
      * Add has-user-setup setting
      
      - iff no user is setup aka has-user-setup == false, then redirect to /setup
      - when set from the env variable the setup-token is completely
        immutable, so can remove clear-token!
      
      * make /api/setup only setup accounts when not has-user-setup
      
      - react router changes to respect 'has-user-setup' setting
      
      - include docstring for print-setup-url
      
      * allow tests to setup multiple users via POST /api/setup
      
      * remove unused function hasSetupToken
      
      * Adds a test to enforce a single creation only
      
      - we now throw an ex-info with status-code 403 when has-user-setup and
        /api/setup route is hit (with error message mentioning the route)
      - more code review responses
      
      - fixup test to not delete users, (or set locale to spanish...)
      
      * addressing code review concerns
      
      - *disallow... -> *allow... for the dynamic var name
      - has-user-settings test: do not assume the test db has users in it
      - update test
      0526d88f
    • Alexander Polyankin's avatar
      Activation fixes for 0.42 (#19947) · 3e73e5d7
      Alexander Polyankin authored
      3e73e5d7
    • Noah Moss's avatar
  5. Jan 26, 2022
  6. Jan 25, 2022
  7. Jan 24, 2022
  8. Jan 21, 2022
  9. Jan 20, 2022
    • Cam Saul's avatar
      `add-alias-info`: recognize `:field` clauses in join source queries to be the... · 33ac1862
      Cam Saul authored
      `add-alias-info`: recognize `:field` clauses in join source queries to be the same if it has a `:temporal-unit` (#19789)
      
      * Backport Debug QP improvements from #19754
      
      * Enable test
      
      * "Fuzzy" matching when looking for Fields in join source queries
      
      * Add/update tests
      
      * Test fix :wrench:
      
      * Remove trailing whitespace
      
      * Fix a few docstrings
      33ac1862
    • Cam Saul's avatar
      Postgres: avoid unnecessary casts of DATE or TIMESTAMPTZ to TIMESTAMP (#19790) · f31221d8
      Cam Saul authored
      * Postgres: avoid unnecessary casts of DATE or TIMESTAMPTZ to TIMESTAMP
      
      * Update src/metabase/util/honeysql_extensions.clj
      
      * Update test/metabase/driver/postgres_test.clj
      f31221d8
    • Cam Saul's avatar
      Don't add `:join-alias` to `:field` clauses for fields that came from source query (#19791) · ed5a4489
      Cam Saul authored
      * Don't add `:join-alias` to `:field` clauses for fields that came from source query's source table
      
      * Some test fixes :wrench:
      
      * Test fixes :wrench:
      
      * Test fix :wrench:
      
      * Test fix :wrench:
      ed5a4489
    • Cam Saul's avatar
      Add test for #7487 (#19810) · 3822d2cd
      Cam Saul authored
      * Add test for #7487
      
      * Fix error message
      
      * Update test for new error message
      3822d2cd
    • Noah Moss's avatar
      491dbdc0
    • Anton Kulyk's avatar
      Preserve metadata changes for models (via editor) (#19724) · 0b7435ee
      Anton Kulyk authored
      
      * RIP checksum
      
      Now that users can edit the metadata the checksum prevents that and
      would throw it away when edited. We'll treat the metadata as valid if it
      conforms. The UI isn't really expected to modify type information anyways.
      
      * Ns checker is a harsh disciplinarian
      
      * Extract `fields` variable in dataset editor
      
      * Allow extra onChange callback to form fields
      
      * Only show metadata sidebar when field is selected
      
      * Add onChange callback to semantic type picker
      
      * Add action for overwriting results metadata
      
      * Connect essential fields to form
      
      * display_name
      * description
      * semantic_type
      
      TBD: mapped database column for native datasets
      
      * Fix missing import
      
      * Fix sidebar inputs loosing focus while typing
      
      * Ensure focused field is in sync
      
      * Refactor FK and currency to be form fields
      
      * Use `field.settings` to keep formatting changes
      
      * Remove "display_as" from form definition
      
      * Connect remaining fields
      
      * Remove CurrencyPicker in favor of formatting input
      
      * Fix incomplete field metadata
      
      Results metadata doesn't contain everything we need for the editor.
      
      'Global' metadata is the most complete, though it shouldn't be muted while in the editor, only once a user saves the changes
      
      Now we only keep focused field ref in state and derive the metadata by merging global metadata and query's results metadata. Query results metadata is mutated by the editor, so merging them both will do the job
      
      * Fix ViewSidebar prop type
      
      * Fix prop type warnings
      
      * Add default values for some fields
      
      * Connect MappedFieldPicker
      
      * Fix MappedFieldPicker closes after loading fields
      
      Sidebar dependant on IDFields was rerendering once additional metadata was loaded, causing DataSelector to unmount
      
      Fixed by moving IDFields subscription to FKTargetPicker directly (the only component that actually needs them)
      
      * Hide metadata popovers in dataset editor
      
      * Disable saving invalid dataset editor changes
      
      Disables "Save changes" button if:
      * there is at least one field with empty display name
      * the underlying query is empty
      
      * Add `onChangeSetting` prop to ColumnSettings
      
      The existing `onChange` passes the whole settings object as an argument. On the other hand, `onChangeSetting` passes only the changed setting which is useful for storing metadata diff
      
      * Keep field metadata diff in redux
      
      * Ignore column width reset events in metadata editor
      
      * Preserve metadata diff between query edits
      
      * A few important changes:
      
      - ensure that we don't throw away metadata and return an empty channel
      in the card api if the query hasn't changed
      - ensure api/dataset uses `:metadata/dataset-metadata`
      - hydrate fields on api/table/card__id/query_metadata so that it has
      target and fk information
      - preserve id so this information can be recovered†
      
      †: When a user enters an id we preserve it, but it also gets confusing
      if that's the actual field's id or the user-identified id. This is
      important when we drill down (and probably lots of other places too if
      they start assuming an id means they know exactly what is going on).
      
      A situation based on the orders table:
      
      Suppose you make a native question
      
      ```sql
      SELECT "PUBLIC"."ORDERS"."ID" AS "ID",
        "PUBLIC"."ORDERS"."USER_ID" AS "user_id_bro",  -- note this is renamed
        "PUBLIC"."ORDERS"."PRODUCT_ID" AS "PRODUCT_ID",
        "PUBLIC"."ORDERS"."SUBTOTAL" AS "SUBTOTAL",
        "PUBLIC"."ORDERS"."TAX" AS "TAX",
        "PUBLIC"."ORDERS"."TOTAL" AS "TOTAL",
        "PUBLIC"."ORDERS"."DISCOUNT" AS "DISCOUNT",
        "PUBLIC"."ORDERS"."CREATED_AT" AS "CREATED_AT",
      "PUBLIC"."ORDERS"."QUANTITY" AS "QUANTITY"
      FROM "PUBLIC"."ORDERS"
      LIMIT 15
      ```
      
      In my db, the "USER_ID" column is field 3 and points at field 22. Our db
      knows that field 3 is called "USER_ID". But in the source query that
      column is actually called "user_id_bro". And lots of places assume that
      if there's a field's `:id` it knows what the name is. This is obviously
      incorrect here. It is a very important distinction that this column "is
      basically field 3 USER_ID" and this is literally the field "USER_ID".
      
      So if you do a drilldown based on this information, the FE will issue a
      query to "select field 3 from card__127" which expands to roughly
      "select USER_ID from (select ... USER_ID as user_id_bro ...)" and this
      query obviously will fail.
      
      * Don't put nil on a channel, clean ns
      
      i honestly don't know why the results-metadata and encrypt deps were
      there. I didn't add them but they just got caught in the linter for some
      reason. I don't understand it.
      
      * Update tests to include target and has_field_values
      
      * Correct final test
      
      * Select enough information for FK to work in UI
      
      * Pass mapped column's properties to BE
      
      * Qualify which semantic_type FK/PK we remove
      
      Previously always removed these semantic types. Now only remove when
      they do not have an id there. One thing I'm confused about though is
      that native fields should never have a semantic type anyways. There's no
      way for one to end up there, certainly not FK or PK right? So i want to
      delete this entire method because as I understand it it's not possible
      to trigger its conditions except for the new user-entered information,
      in which case we want to preserve it. But I have no idea why
      Mr. Chesterton built this function so I don't want to delete it.
      
      Bug reports and connecting them back to this change is so hard. Because
      it can be things like "native query with an aggregation named "blah"
      bucketed by month break when you drilldown into this column" and that's
      because it includes a semantic_type that breaks something. It's all very
      at-a-distance so hard to trace back to this.
      
      * Fix failed queries handling
      
      * Support custom column metadata editing
      
      * Hide empty sections in semantic type picker
      
      * Remove redundant import
      
      * Fetch database ID fields in FKTargetPicker
      
      * Allow aliasing EntityObjectLoader's entity prop
      
      * Reset DataSelector's state when ID props change
      
      * Fix MappedFieldPicker
      
      * Fixed saved question picker regression
      
      * Select description and settings when merging result_metadata
      
      Annotate columns allows for settings to be preserved from
      datasets. Example
      
      ```clojure
      ;; shows a little bar in the UI. quite nice
      :settings {:show_mini_bar true, :decimals 0},
      ```
      
      These settings were correctly preserved in annotate.clj but dropped in
      the final merging in result_metadata.clj. Fun times in metadata land
      
      * Let dataset revisions preserve metadata
      
      * Only wrap form fields with custom onChange handler
      
      This prevents form fields from extra re-renders
      
      * Fix summarize sidebar behavior
      
      * Fix e2e test
      
      * Update cypress expectations
      
      Previously expected really generic placeholder text in search boxes. But
      in `api/table/card__id/query_metadata` we hydrate native columns with
      `:has_field_values` so that when a user identifies an underlying field
      on datasets, we have extra information.
      
      This change comes about because the hydrate for `:has_field_values`
      doesn't hit the db and look for field values but uses a heuristic.  And
      this heuristic works for native fields and finds that they are
      searchable because when they are text or textlike and improves the
      search bar.
      
      Code from models/field.clj below
      
      ```clojure
      (defn- is-searchable?
        "Is this `field` a Field that you should be presented with a search widget for (to search its values)? If so, we can
        give it a `has_field_values` value of `search`."
        [{base-type :base_type}]
        ;; For the time being we will consider something to be "searchable" if it's a text Field since the `starts-with`
        ;; filter that powers the search queries (see `metabase.api.field/search-values`) doesn't work on anything else
        (or (isa? base-type :type/Text)
            (isa? base-type :type/TextLike)))
      
      (defn- infer-has-field-values
        "Determine the value of `has_field_values` we should return for a `Field` As of 0.29.1 this doesn't require any DB
        calls! :D"
        [{has-field-values :has_field_values, :as field}]
        (or
         ;; if `has_field_values` is set in the DB, use that value; but if it's `auto-list`, return the value as `list` to
         ;; avoid confusing FE code, which can remain blissfully unaware that `auto-list` is a thing
         (when has-field-values
           (if (= (keyword has-field-values) :auto-list)
             :list
             has-field-values))
         ;; otherwise if it does not have value set in DB we will infer it
         (if (is-searchable? field)
           :search
           :none)))
      
      (defn with-has-field-values
        "Infer what the value of the `has_field_values` should be for Fields where it's not set. See documentation for
        `has-field-values-options` above for a more detailed explanation of what these values mean."
        {:batched-hydrate :has_field_values}
        [fields]
        (for [field fields]
          (when field
            (assoc field :has_field_values (infer-has-field-values field)))))
      ```
      
      * Ignore `has_field_values` for field literals
      
      Field literals are field using a column title instead of a numeric ID. They're usually coming from native or nested queries.
      
      Metadata propagation changes introduced for data models, made the BE send a guessed `has_field_values` property for field literals too. But searching through possible field values isn't properly supported yet and it's difficult to prevent `has_field_values` being sent to the FE, so this makes the FE ignore it for field literals
      
      * Fix E2E test
      
      * Fix field literal check
      
      * Ensure `:has_field_values` only goes on fields with ids
      
      when a user selects an id to back a native field, we want to hydrate the
      field_value information and the target info. But _ONLY_ when they have
      ids. The hydration for `:has_field_values` works on a heuristic, not by
      hitting the db and seeing if we have field values and will give
      information about native fields that do not have backing field information.
      
      * Ensure no annotations on numeric field ids
      
      we put the vector id on each field when there's no numeric id field. I
      have no idea why and the comment `;; TODO -- what????` explains the
      thinking there. So only annotate where we have numeric ids (fields that
      we know how to identify fields in the db) and not when we have a made up
      vector id
      
      * Revert changes to FieldValuesWidget
      
      * Fix character case
      
      * Show `has_field_values` selector when ID is known
      
      * Undo the testing for indiscriminant hydration
      
      previously had put target and has_field_values on every native field
      which doesn't work well for the UI. Had to clean up the remaining tests
      to no longer expect it
      
      * Select `:dataset` when creating a new question
      
      when duplicating a question, we send over this info and need to select
      it from the existing question.
      
      * Ensure card is saved with boolean dataset info
      
      largely just for testing which does not send a `:dataset false` property
      in some cases. In regular usage there should always be an initial value
      
      * Remove dead code
      
      * Replace TODO with a meaningful comment
      
      * Type Field type
      
      * Select only what we need on the source card
      
      Co-authored-by: default avatardan sutton <dan@dpsutton.com>
      0b7435ee
  10. Jan 19, 2022
Loading